Index: /branches/libffado-2.0/src/libieee1394/ieee1394service.cpp =================================================================== --- /branches/libffado-2.0/src/libieee1394/ieee1394service.cpp (revision 1163) +++ /branches/libffado-2.0/src/libieee1394/ieee1394service.cpp (revision 1190) @@ -25,5 +25,4 @@ #include "config.h" #include "ieee1394service.h" -#include "ARMHandler.h" #include "cycletimer.h" #include "IsoHandlerManager.h" @@ -107,15 +106,4 @@ delete m_pCTRHelper; stopRHThread(); - for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); - it != m_armHandlers.end(); - ++it ) - { - debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler for 0x%016llX\n", (*it)->getStart()); - int err=raw1394_arm_unregister(m_resetHandle, (*it)->getStart()); - if (err) { - debugError(" Failed to unregister ARM handler for 0x%016llX\n", (*it)->getStart()); - debugError(" Error: %s\n", strerror(errno)); - } - } delete m_pWatchdog; @@ -266,7 +254,4 @@ this->resetHandlerLowLevel ); - m_default_arm_handler = raw1394_set_arm_tag_handler( m_resetHandle, - this->armHandlerLowLevel ); - if(!m_pCTRHelper) { debugFatal("No CycleTimerHelper available, bad!\n"); @@ -640,145 +625,4 @@ } - return true; -} - -bool Ieee1394Service::registerARMHandler(ARMHandler *h) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Registering ARM handler (%p) for 0x%016llX, length %u\n", - h, h->getStart(), h->getLength()); - - int err=raw1394_arm_register(m_resetHandle, h->getStart(), - h->getLength(), h->getBuffer(), (octlet_t)h, - h->getAccessRights(), - h->getNotificationOptions(), - h->getClientTransactions()); - if (err) { - debugError("Failed to register ARM handler for 0x%016llX\n", h->getStart()); - debugError(" Error: %s\n", strerror(errno)); - return false; - } - - m_armHandlers.push_back( h ); - - return true; -} - -bool Ieee1394Service::unregisterARMHandler( ARMHandler *h ) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler (%p) for 0x%016llX\n", - h, h->getStart()); - - for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); - it != m_armHandlers.end(); - ++it ) - { - if((*it) == h) { - int err=raw1394_arm_unregister(m_resetHandle, h->getStart()); - if (err) { - debugError("Failed to unregister ARM handler (%p)\n", h); - debugError(" Error: %s\n", strerror(errno)); - } else { - m_armHandlers.erase(it); - return true; - } - } - } - debugOutput(DEBUG_LEVEL_VERBOSE, " handler not found!\n"); - - return false; -} -/** - * @brief Tries to find a free ARM address range - * - * @param start address to start with - * @param length length of the block needed (bytes) - * @param step step to use when searching (bytes) - * @return The base address that is free, and 0xFFFFFFFFFFFFFFFF when failed - */ -nodeaddr_t Ieee1394Service::findFreeARMBlock( nodeaddr_t start, size_t length, size_t step ) { - debugOutput(DEBUG_LEVEL_VERBOSE, "Finding free ARM block of %d bytes, from 0x%016llX in steps of %d bytes\n", - length, start, step); - - int cnt=0; - const int maxcnt=10; - int err=1; - while(err && cnt++ < maxcnt) { - // try to register - err=raw1394_arm_register(m_resetHandle, start, length, 0, 0, 0, 0, 0); - - if (err) { - debugOutput(DEBUG_LEVEL_VERBOSE, " -> cannot use 0x%016llX\n", start); - debugError(" Error: %s\n", strerror(errno)); - start += step; - } else { - debugOutput(DEBUG_LEVEL_VERBOSE, " -> use 0x%016llX\n", start); - err=raw1394_arm_unregister(m_resetHandle, start); - if (err) { - debugOutput(DEBUG_LEVEL_VERBOSE, " error unregistering test handler\n"); - debugError(" Error: %s\n", strerror(errno)); - return 0xFFFFFFFFFFFFFFFFLLU; - } - return start; - } - } - debugOutput(DEBUG_LEVEL_VERBOSE, " Could not find free block in %d tries\n",cnt); - return 0xFFFFFFFFFFFFFFFFLLU; -} - -int -Ieee1394Service::armHandlerLowLevel(raw1394handle_t handle, - unsigned long arm_tag, - byte_t request_type, unsigned int requested_length, - void *data) -{ - Ieee1394Service* instance - = (Ieee1394Service*) raw1394_get_userdata( handle ); - instance->armHandler( arm_tag, request_type, requested_length, data ); - - return 0; -} - -bool -Ieee1394Service::armHandler( unsigned long arm_tag, - byte_t request_type, unsigned int requested_length, - void *data) -{ - for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); - it != m_armHandlers.end(); - ++it ) - { - if((*it) == (ARMHandler *)arm_tag) { - struct raw1394_arm_request_response *arm_req_resp; - arm_req_resp = (struct raw1394_arm_request_response *) data; - raw1394_arm_request_t arm_req=arm_req_resp->request; - raw1394_arm_response_t arm_resp=arm_req_resp->response; - - debugOutput(DEBUG_LEVEL_VERBOSE,"ARM handler for address 0x%016llX called\n", - (*it)->getStart()); - debugOutput(DEBUG_LEVEL_VERBOSE," request type : 0x%02X\n",request_type); - debugOutput(DEBUG_LEVEL_VERBOSE," request length : %04d\n",requested_length); - - switch(request_type) { - case RAW1394_ARM_READ: - (*it)->handleRead(arm_req); - *arm_resp=*((*it)->getResponse()); - break; - case RAW1394_ARM_WRITE: - (*it)->handleWrite(arm_req); - *arm_resp=*((*it)->getResponse()); - break; - case RAW1394_ARM_LOCK: - (*it)->handleLock(arm_req); - *arm_resp=*((*it)->getResponse()); - break; - default: - debugWarning("Unknown request type received, ignoring...\n"); - } - - return true; - } - } - - debugOutput(DEBUG_LEVEL_VERBOSE,"default ARM handler called\n"); - - m_default_arm_handler(m_resetHandle, arm_tag, request_type, requested_length, data ); return true; } Index: /branches/libffado-2.0/src/libieee1394/ieee1394service.h =================================================================== --- /branches/libffado-2.0/src/libieee1394/ieee1394service.h (revision 1161) +++ /branches/libffado-2.0/src/libieee1394/ieee1394service.h (revision 1190) @@ -40,5 +40,4 @@ #include -class ARMHandler; class IsoHandlerManager; class CycleTimerHelper; @@ -246,22 +245,4 @@ return raw1394_get_generation( m_handle ); } - - /** - * @brief register an AddressRangeMapping Handler - * @param h pointer to the handler to register - * - * @return true on success or false on failure - **/ - - bool registerARMHandler( ARMHandler *h ); - - /** - * @brief unregister ARM range - * @param h pointer to the handler to unregister - * @return true if successful, false otherwise - */ - bool unregisterARMHandler( ARMHandler *h ); - - nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step ); // ISO channel stuff @@ -310,11 +291,4 @@ bool resetHandler( unsigned int generation ); - static int armHandlerLowLevel(raw1394handle_t handle, unsigned long arm_tag, - byte_t request_type, unsigned int requested_length, - void *data); - bool armHandler( unsigned long arm_tag, - byte_t request_type, unsigned int requested_length, - void *data); - raw1394handle_t m_handle; Util::Mutex* m_handle_lock; @@ -341,10 +315,4 @@ reset_handler_vec_t m_busResetHandlers; - // ARM stuff - arm_tag_handler_t m_default_arm_handler; - - typedef std::vector< ARMHandler * > arm_handler_vec_t; - arm_handler_vec_t m_armHandlers; - public: void setVerboseLevel(int l); Index: /anches/libffado-2.0/src/libieee1394/test-cyclecalc.cpp =================================================================== --- /branches/libffado-2.0/src/libieee1394/test-cyclecalc.cpp (revision 1047) +++ (revision ) @@ -1,87 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "cycletimer.h" -#include "debugmodule/debugmodule.h" -#include - -DECLARE_GLOBAL_DEBUG_MODULE; - -int main() { - setDebugLevel(DEBUG_LEVEL_VERY_VERBOSE); - printf("Cycle timer operation tests (incomplete)\n"); - - /* TEST 1 - * check reconstruction of SYT RECEIVE timestamp - * - * The now_ctr has wrapped, while the cycle and syt have not - * - */ - - #ifdef DEBUG - uint32_t now_ctr = 0x140001DA; - uint64_t now = CYCLE_TIMER_TO_TICKS(0x140001DA); - unsigned int cycle = 7968; - uint16_t syt = 0x583B; - #endif - - debugOutput(DEBUG_LEVEL_VERBOSE,"NOW_CTR : %08X (%03us %04uc %04ut)\n", - now_ctr, - (unsigned int)CYCLE_TIMER_GET_SECS(now_ctr), - (unsigned int)CYCLE_TIMER_GET_CYCLES(now_ctr), - (unsigned int)CYCLE_TIMER_GET_OFFSET(now_ctr)); - - debugOutput(DEBUG_LEVEL_VERBOSE,"NOW : %011llu (%03us %04uc %04ut)\n", - now, - (unsigned int)TICKS_TO_SECS(now), - (unsigned int)TICKS_TO_CYCLES(now), - (unsigned int)TICKS_TO_OFFSET(now)); - debugOutput(DEBUG_LEVEL_VERBOSE,"SYT : %08X (%03us %04uc %04ut)\n", - syt, - (unsigned int)CYCLE_TIMER_GET_SECS(syt), - (unsigned int)CYCLE_TIMER_GET_CYCLES(syt), - (unsigned int)CYCLE_TIMER_GET_OFFSET(syt)); - debugOutput(DEBUG_LEVEL_VERBOSE,"CYCLE : %uc\n", - cycle); - #ifdef DEBUG - uint64_t calc_ts = sytRecvToFullTicks(syt, cycle, now_ctr); - #endif - - debugOutput(DEBUG_LEVEL_VERBOSE,"CALC_TS : %011llu (%03us %04uc %04ut)\n", - calc_ts, - (unsigned int)TICKS_TO_SECS(calc_ts), - (unsigned int)TICKS_TO_CYCLES(calc_ts), - (unsigned int)TICKS_TO_OFFSET(calc_ts)); - - -// BL: 1211722982: Debug (IsoHandler.cpp)[ 420] putPacket: received packet: length=168, channel=0, cycle=7968 -// BL: 1211723031: Debug (cycletimer.h)[ 308] sytRecvToFullTicks: SYT=583B CY=7968 CTR=140001DA -// BL: 1211723037: Debug (StreamProcessor.cpp)[ 346] putPacket: RECV: CY=7968 TS=00245679163 -// BL: 1211723043: Debug (AmdtpReceiveStreamProcessor.cpp)[ 135] processPacketData: STMP: 245679163ticks | syt_interval=8, tpf=557.254395 -// BL: 1211723051: Debug (TimestampedBuffer.cpp)[1153] incrementFrameCounter: nbframes: 8, m_update_period: 8 -// BL: 1211723052: Debug (AmdtpTransmitStreamProcessor.cpp)[ 250] generatePacketHeader: Too early: CY=0254, TC=0257, CUT=0003, TST=00271126073 (0257), TSP=00271137849 (0261) -// BL: 1211723055: Debug (TimestampedBuffer.cpp)[1155] incrementFrameCounter: tail TS: 270250705.174, next tail TS: 270255163.209 -// BL: 1211723062: Debug (TimestampedBuffer.cpp)[1157] incrementFrameCounter: new TS: 245679163.000, wrapped new TS: 245679163.000 -// - -} Index: /branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h =================================================================== --- /branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h (revision 1036) +++ /branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h (revision 1190) @@ -29,5 +29,4 @@ #include "PortManager.h" -#include "libutil/StreamStatistics.h" #include "libutil/TimestampedBuffer.h" #include "libutil/OptionContainer.h" Index: /branches/libffado-2.0/src/motu/motu_avdevice.cpp =================================================================== --- /branches/libffado-2.0/src/motu/motu_avdevice.cpp (revision 1158) +++ /branches/libffado-2.0/src/motu/motu_avdevice.cpp (revision 1190) @@ -36,5 +36,4 @@ #include "libstreaming/motu/MotuPort.h" -#include "libutil/DelayLockedLoop.h" #include "libutil/Time.h" Index: /branches/libffado-2.0/src/SConscript =================================================================== --- /branches/libffado-2.0/src/SConscript (revision 1185) +++ /branches/libffado-2.0/src/SConscript (revision 1190) @@ -72,14 +72,8 @@ libstreaming/generic/PortManager.cpp \ libutil/cmd_serialize.cpp \ - libutil/DelayLockedLoop.cpp \ - libutil/IpcRingBuffer.cpp \ - libutil/PacketBuffer.cpp \ libutil/OptionContainer.cpp \ - libutil/PosixMessageQueue.cpp \ - libutil/PosixSharedMemory.cpp \ libutil/PosixMutex.cpp \ libutil/PosixThread.cpp \ libutil/ringbuffer.c \ - libutil/StreamStatistics.cpp \ libutil/SystemTimeSource.cpp \ libutil/TimestampedBuffer.cpp \ @@ -114,12 +108,8 @@ bebob/terratec/terratec_device.cpp \ bebob/terratec/terratec_cmd.cpp \ - bebob/edirol/edirol_fa101.cpp \ + bebob/edirol/edirol_fa101.cpp \ bebob/esi/quatafire610.cpp \ - maudio/maudio_avdevice.cpp \ ' ) bebob_pkgdata = env.Split( '\ - maudio/refdesign.xml \ - maudio/fw410.xml \ - maudio/fwap.xml \ bebob/ffado_driver_bebob.txt \ ' ) @@ -131,5 +121,5 @@ genericavc_pkgdata = env.Split( '\ - genericavc/ffado_driver_genericavc.txt \ + genericavc/ffado_driver_genericavc.txt \ ' ) @@ -150,5 +140,5 @@ fireworks_pkgdata = env.Split( '\ - fireworks/ffado_driver_fireworks.txt \ + fireworks/ffado_driver_fireworks.txt \ ' ) @@ -162,22 +152,4 @@ ' ) -dice_source = env.Split( '\ - dice/dice_avdevice.cpp \ -' ) - -bounce_source = env.Split( '\ - bounce/bounce_avdevice.cpp \ - bounce/bounce_slave_avdevice.cpp \ - libstreaming/AmdtpSlaveStreamProcessor.cpp \ -' ) - -metric_halo_source = env.Split( '\ - metrichalo/mh_avdevice.cpp \ -' ) - -rme_source = env.Split( '\ - rme/rme_avdevice.cpp \ -' ) - amdtp_source = env.Split( '\ libstreaming/amdtp/AmdtpPort.cpp \ @@ -186,5 +158,4 @@ libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp \ ' ) - source = ffado_source @@ -201,16 +172,4 @@ libenv.AppendUnique( CCFLAGS=["-DENABLE_MOTU"] ) source += motu_source -if env['ENABLE_DICE']: - libenv.AppendUnique( CCFLAGS=["-DENABLE_DICE"] ) - source += dice_source -if env['ENABLE_METRIC_HALO']: - libenv.AppendUnique( CCFLAGS=["-DENABLE_METRIC_HALO"] ) - source += metric_halo_source -if env['ENABLE_RME']: - libenv.AppendUnique( CCFLAGS=["-DENABLE_RME"] ) - source += rme_source -if env['ENABLE_BOUNCE']: - libenv.AppendUnique( CCFLAGS=["-DENABLE_BOUNCE"] ) - source += bounce_source # The list of devices needing GENERICAVC is controlled in ../SConstruct @@ -280,8 +239,4 @@ apps = { \ - "test-debugmodule" : "debugmodule/test_debugmodule.cpp", \ - "test-dll" : "libutil/test-dll.cpp", \ - "test-unittests-util" : "libutil/unittests.cpp", \ - "test-cyclecalc" : "libieee1394/test-cyclecalc.cpp", \ } Index: /anches/libffado-2.0/src/libutil/PacketBuffer.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/PacketBuffer.cpp (revision 864) +++ (revision ) @@ -1,139 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "PacketBuffer.h" -#include - - -namespace Streaming { - -IMPL_DEBUG_MODULE( PacketBuffer, PacketBuffer, DEBUG_LEVEL_VERBOSE ); - - -PacketBuffer::~PacketBuffer() { - if(payload_buffer) ffado_ringbuffer_free(payload_buffer); - if(header_buffer) ffado_ringbuffer_free(header_buffer); - if(len_buffer) ffado_ringbuffer_free(len_buffer); -} - -int PacketBuffer::initialize() { - debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); - - if(payload_buffer) ffado_ringbuffer_free(payload_buffer); - if(header_buffer) ffado_ringbuffer_free(header_buffer); - if(len_buffer) ffado_ringbuffer_free(len_buffer); - - payload_buffer=ffado_ringbuffer_create(m_buffersize * m_max_packetsize * sizeof(quadlet_t)); - if(!payload_buffer) { - debugFatal("Could not allocate payload buffer\n"); - return -1; - } - - header_buffer=ffado_ringbuffer_create(m_buffersize * (m_headersize) * sizeof(quadlet_t)); - if(!header_buffer) { - debugFatal("Could not allocate header buffer\n"); - return -1; - } - - len_buffer=ffado_ringbuffer_create(m_buffersize * sizeof(unsigned int)); - if(!len_buffer) { - debugFatal("Could not allocate len buffer\n"); - return -1; - } - debugOutput( DEBUG_LEVEL_VERBOSE, "exit...\n"); - - return 0; -} - -void PacketBuffer::flush() { - if(header_buffer) { - ffado_ringbuffer_reset(header_buffer); - } - if(payload_buffer) { - ffado_ringbuffer_reset(payload_buffer); - } - if(len_buffer) { - ffado_ringbuffer_reset(len_buffer); - } -} - -int PacketBuffer::addPacket(quadlet_t *packet, int packet_len) { - - unsigned int payload_bytes=sizeof(quadlet_t)*(packet_len-m_headersize); - unsigned int header_bytes=sizeof(quadlet_t)*(m_headersize); - - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, - "add packet: length=%d\n", - packet_len); - - if ((ffado_ringbuffer_write_space(payload_buffer) > payload_bytes) - && (ffado_ringbuffer_write_space(header_buffer) > header_bytes)) { - - ffado_ringbuffer_write(payload_buffer,(char *)(packet)+header_bytes, payload_bytes); - ffado_ringbuffer_write(len_buffer,(char *)(&payload_bytes),sizeof(unsigned int)); - ffado_ringbuffer_write(header_buffer,(char *)(packet), header_bytes); - - } else return -1; - return 0; - -} - -int PacketBuffer::getNextPacket(quadlet_t *packet, int max_packet_len) { - - unsigned int bytes=sizeof(quadlet_t)*(m_headersize); - quadlet_t *ptr=packet+m_headersize; - - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, - "getNextPacket\n"); - - if(max_packet_len(max_packet_len-m_headersize)*sizeof(quadlet_t)) return -2; - - if(ffado_ringbuffer_read(payload_buffer,(char *)(ptr),bytes) < bytes) { - return -3; - } - - return bytes/sizeof(quadlet_t)+m_headersize; -} - -int PacketBuffer::getBufferFillPackets() { - - return ffado_ringbuffer_read_space(len_buffer)/sizeof(unsigned int); -} - -// in quadlets -int PacketBuffer::getBufferFillPayload() { - - return ffado_ringbuffer_read_space(payload_buffer)/sizeof(quadlet_t); -} - -} Index: /anches/libffado-2.0/src/libutil/unittests.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/unittests.cpp (revision 1154) +++ (revision ) @@ -1,560 +1,0 @@ -/* unittests.cpp - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "serialize.h" -#include "OptionContainer.h" - -#include - -#include - -using namespace Util; - -#define TEST_SHOULD_RETURN_TRUE(test) \ - (test ? true : printf( "'" #test "' should return true\n") && false ) -#define TEST_SHOULD_RETURN_FALSE(test) \ - (test ? printf( "'" #test "' should return true\n") && false : true ) - -/////////////////////////////////////// - -class U0_SerializeMe { -public: - U0_SerializeMe(); - - bool operator == ( const U0_SerializeMe& rhs ); - - bool serialize( IOSerialize& ser ); - bool deserialize( IODeserialize& deser ); - - byte_t m_byte; - quadlet_t m_quadlet; -}; - -U0_SerializeMe::U0_SerializeMe() - : m_byte( 0 ) - , m_quadlet( 0 ) -{ -} - - -//-------------------------- -bool -U0_SerializeMe::operator == ( const U0_SerializeMe& rhs ) -{ - return ( m_byte == rhs.m_byte ) - && ( m_quadlet == rhs.m_quadlet ); -} - -bool -U0_SerializeMe::serialize( IOSerialize& ser ) -{ - bool result; - result = ser.write( "SerializeMe/m_byte", m_byte ); - result &= ser.write( "SerializeMe/m_quadlet", m_quadlet ); - return result; -} - -bool -U0_SerializeMe::deserialize( IODeserialize& deser ) -{ - bool result; - result = deser.read( "SerializeMe/m_byte", m_byte ); - result &= deser.read( "SerializeMe/m_quadlet", m_quadlet ); - return result; -} - -static bool -testU0() -{ - U0_SerializeMe sme1; - - sme1.m_byte = 0x12; - sme1.m_quadlet = 0x12345678; - - { - XMLSerialize xmlSerialize( "unittest_u0.xml" ); - if ( !sme1.serialize( xmlSerialize ) ) { - printf( "(serializing failed)" ); - return false; - } - } - - U0_SerializeMe sme2; - - { - XMLDeserialize xmlDeserialize( "unittest_u0.xml" ); - if ( !sme2.deserialize( xmlDeserialize ) ) { - printf( "(deserializing failed)" ); - return false; - } - } - - bool result = sme1 == sme2; - if ( !result ) { - printf( "(wrong values)" ); - } - return result; -} - - -/////////////////////////////////////// - -class U1_SerializeMe { -public: - U1_SerializeMe(); - - bool operator == ( const U1_SerializeMe& rhs ); - - bool serialize( IOSerialize& ser ); - bool deserialize( IODeserialize& deser ); - - quadlet_t m_quadlet0; - quadlet_t m_quadlet1; - quadlet_t m_quadlet2; -}; - -U1_SerializeMe::U1_SerializeMe() - : m_quadlet0( 0 ) - , m_quadlet1( 0 ) - , m_quadlet2( 0 ) -{ -} - - -//-------------------------- -bool -U1_SerializeMe::operator == ( const U1_SerializeMe& rhs ) -{ - return ( m_quadlet0 == rhs.m_quadlet0 ) - && ( m_quadlet1 == rhs.m_quadlet1) - && ( m_quadlet2 == rhs.m_quadlet2); -} - -bool -U1_SerializeMe::serialize( IOSerialize& ser ) -{ - bool result; - result = ser.write( "here/and/not/there/m_quadlet0", m_quadlet0 ); - result &= ser.write( "here/and/not/m_quadlet1", m_quadlet1 ); - result &= ser.write( "here/and/m_quadlet2", m_quadlet2 ); - return result; -} - -bool -U1_SerializeMe::deserialize( IODeserialize& deser ) -{ - bool result; - result = deser.read( "here/and/not/there/m_quadlet0", m_quadlet0 ); - result &= deser.read( "here/and/not/m_quadlet1", m_quadlet1 ); - result &= deser.read( "here/and/m_quadlet2", m_quadlet2 ); - return result; -} - -static bool -testU1() -{ - U1_SerializeMe sme1; - - sme1.m_quadlet0 = 0; - sme1.m_quadlet1 = 1; - sme1.m_quadlet2 = 2; - - { - XMLSerialize xmlSerialize( "unittest_u1.xml" ); - if ( !sme1.serialize( xmlSerialize ) ) { - printf( "(serializing failed)" ); - return false; - } - } - - U1_SerializeMe sme2; - - { - XMLDeserialize xmlDeserialize( "unittest_u1.xml" ); - if ( !sme2.deserialize( xmlDeserialize ) ) { - printf( "(deserializing failed)" ); - return false; - } - } - - bool result = sme1 == sme2; - if ( !result ) { - printf( "(wrong values)" ); - } - return result; -} - -/////////////////////////////////////// - -class U2_SerializeMe { -public: - U2_SerializeMe(); - - bool operator == ( const U2_SerializeMe& rhs ); - - bool serialize( IOSerialize& ser ); - bool deserialize( IODeserialize& deser ); - - char m_char; - unsigned char m_unsigned_char; - short m_short; - unsigned short m_unsigned_short; - int m_int; - unsigned int m_unsigned_int; -}; - -U2_SerializeMe::U2_SerializeMe() - : m_char( 0 ) - , m_unsigned_char( 0 ) - , m_short( 0 ) - , m_unsigned_short( 0 ) - , m_int( 0 ) - , m_unsigned_int( 0 ) -{ -} - -//-------------------------- - -bool -U2_SerializeMe::operator == ( const U2_SerializeMe& rhs ) -{ - return ( m_char == rhs.m_char ) - && ( m_unsigned_char == rhs.m_unsigned_char ) - && ( m_short == rhs.m_short ) - && ( m_unsigned_short == rhs.m_unsigned_short ) - && ( m_int == rhs.m_int ) - && ( m_unsigned_int == rhs.m_unsigned_int ); -} - -bool -U2_SerializeMe::serialize( IOSerialize& ser ) -{ - bool result; - result = ser.write( "m_char", m_char ); - result &= ser.write( "m_unsigned_char", m_unsigned_char ); - result &= ser.write( "m_short", m_short ); - result &= ser.write( "m_unsigned_short", m_unsigned_short ); - result &= ser.write( "m_int", m_int ); - result &= ser.write( "m_unsigned_int", m_unsigned_int ); - return result; -} - -bool -U2_SerializeMe::deserialize( IODeserialize& deser ) -{ - bool result; - result = deser.read( "m_char", m_char ); - result &= deser.read( "m_unsigned_char", m_unsigned_char ); - result &= deser.read( "m_short", m_short ); - result &= deser.read( "m_unsigned_short", m_unsigned_short ); - result &= deser.read( "m_int", m_int ); - result &= deser.read( "m_unsigned_int", m_unsigned_int ); - return result; -} - -static bool -testU2execute( U2_SerializeMe& sme1 ) -{ - { - XMLSerialize xmlSerialize( "unittest_u2.xml" ); - if ( !sme1.serialize( xmlSerialize ) ) { - printf( "(serializing failed)" ); - return false; - } - } - - U2_SerializeMe sme2; - - { - XMLDeserialize xmlDeserialize( "unittest_u2.xml" ); - if ( !sme2.deserialize( xmlDeserialize ) ) { - printf( "(deserializing failed)" ); - return false; - } - } - - bool result = sme1 == sme2; - if ( !result ) { - printf( "(wrong values)" ); - } - - return result; -} - -static bool -testU2() -{ - U2_SerializeMe sme1; - - sme1.m_char = 0; - sme1.m_unsigned_char = 1; - sme1.m_short = 2; - sme1.m_unsigned_short = 3; - sme1.m_int = 4; - sme1.m_unsigned_int = 5; - - bool result; - result = testU2execute( sme1 ); - - sme1.m_char = 0xff; - sme1.m_unsigned_char = 0xff; - sme1.m_short = 0xffff; - sme1.m_unsigned_short = 0xffff; - sme1.m_int = 0xffffffff; - sme1.m_unsigned_int = 0xffffffff; - - result &= testU2execute( sme1 ); - - return result; -} - -/////////////////////////////////////// - -class U3_SerializeMe { -public: - U3_SerializeMe(); - ~U3_SerializeMe(); - - bool operator == ( const U3_SerializeMe& rhs ); - - bool serialize( IOSerialize& ser ); - bool deserialize( IODeserialize& deser ); - - const char* m_pString; -}; - -U3_SerializeMe::U3_SerializeMe() - : m_pString( 0 ) -{ -} - - -U3_SerializeMe::~U3_SerializeMe() -{ - delete m_pString; -} -//-------------------------- - -bool -U3_SerializeMe::operator == ( const U3_SerializeMe& rhs ) -{ - return strcmp( m_pString, rhs.m_pString ) == 0; -} - -bool -U3_SerializeMe::serialize( IOSerialize& ser ) -{ - bool result; - result = ser.write( "m_pString", std::string( m_pString ) ); - return result; -} - -bool -U3_SerializeMe::deserialize( IODeserialize& deser ) -{ - bool result; - std::string str; - result = deser.read( "m_pString", str ); - - m_pString = strdup( str.c_str() ); - - return result; -} - -static bool -testU3() -{ - U3_SerializeMe sme1; - sme1.m_pString = strdup( "fancy string" ); - - { - XMLSerialize xmlSerialize( "unittest_u3.xml" ); - if ( !sme1.serialize( xmlSerialize ) ) { - printf( "(serializing failed)" ); - return false; - } - } - - U3_SerializeMe sme2; - - { - XMLDeserialize xmlDeserialize( "unittest_u3.xml" ); - if ( !sme2.deserialize( xmlDeserialize ) ) { - printf( "(deserializing failed)" ); - return false; - } - } - - bool result = sme1 == sme2; - if ( !result ) { - printf( "(wrong values)" ); - } - - return result; -} - -///////////////////////////////////// -class testOC : public OptionContainer { -public: - testOC() {}; - ~testOC() {}; - - bool test() { - bool result=true; - - Option op1=Option(); - result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); - - op1=Option("option1"); - result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); - - op1=Option("option1", (float)(1.0)); - result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); - result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); - result &= TEST_SHOULD_RETURN_TRUE(removeOption(op1)); - result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); - - - op1=Option("option1", (int64_t)1); - result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); - - result &= TEST_SHOULD_RETURN_TRUE(removeOption("option1")); - - result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); - - - op1=Option("option1", (int64_t)(-1)); - result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); - - Option op2=Option("option1", (double)(1.75)); - result &= TEST_SHOULD_RETURN_FALSE(addOption(op2)); - - - op2=Option("option2", (double)(1.75)); - result &= TEST_SHOULD_RETURN_TRUE(addOption(op2)); - - Option op3=Option("option3", (int64_t)(1.75)); - result &= TEST_SHOULD_RETURN_TRUE(addOption(op3)); - - - result &= TEST_SHOULD_RETURN_TRUE(countOptions() == 3); - - int i=0; - for ( OptionContainer::iterator it = begin(); - it != end(); - ++it ) - { - // printf(" (%s)",(*it).getName().c_str()); - i++; - } - result &= TEST_SHOULD_RETURN_TRUE(i==3); - - clearOptions(); - return result; - } - - void prepare() { - Option op1=Option("option1", (int64_t)(-1)); - if(!addOption(op1)) { - printf( "prepare: could not add valid option (3)\n" ); - } - - Option op2=Option("option2", (double)(1.75)); - if(!addOption(op2)) { - printf( "prepare: adding an option with a different name should be allowed (1)\n" ); - } - Option op3=Option("option3", (int64_t)(1.75)); - if(!addOption(op3)) { - printf( "prepare: adding an option with a different name should be allowed (2)\n" ); - } - } -}; - -static bool -testU4() -{ - bool result=true; - testOC oc; - result &= TEST_SHOULD_RETURN_TRUE(oc.test()); - - // now manipulate it externally - oc.prepare(); - - result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option1")); - result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option2")); - result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option3")); - result &= TEST_SHOULD_RETURN_FALSE(oc.hasOption("option4")); - - oc.setOption("option1", 1024); - int tst; - result &= TEST_SHOULD_RETURN_TRUE(oc.getOption("option1", tst)); - result &= TEST_SHOULD_RETURN_TRUE(tst == 1024); - - return result; -} - -///////////////////////////////////// -///////////////////////////////////// -///////////////////////////////////// - - -typedef bool ( *test_func ) (); -struct TestEntry { - const char* m_pName; - test_func m_pFunc; -}; - -TestEntry TestTable[] = { - { "serialize 0", testU0 }, - { "serialize 1", testU1 }, - { "serialize 2", testU2 }, - { "serialize 3", testU3 }, - { "OptionContainer 1", testU4 }, -}; - -int -main( int argc, char** argv ) -{ - int iNrOfPassedTests = 0; - int iNrOfFailedTests = 0; - int iNrOfTests = sizeof( TestTable )/sizeof( TestTable[0] ); - - for ( int i = 0; i < iNrOfTests ; ++i ) { - TestEntry* pEntry = &TestTable[i]; - - printf( "Test \"%s\"... ", pEntry->m_pName ); - if ( pEntry->m_pFunc() ) { - puts( " passed" ); - iNrOfPassedTests++; - } else { - puts( " failed" ); - iNrOfFailedTests++; - } - } - - printf( "passed: %d\n", iNrOfPassedTests ); - printf( "failed: %d\n", iNrOfFailedTests ); - printf( "total: %d\n", iNrOfTests ); - - return 0; -} Index: /anches/libffado-2.0/src/libutil/PosixMessageQueue.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/PosixMessageQueue.cpp (revision 1172) +++ (revision ) @@ -1,414 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "PosixMessageQueue.h" - -#include "Functors.h" -#include "PosixMutex.h" - -#include -#include - -#define MQ_INVALID_ID ((mqd_t) -1) -// one second -#define POSIX_MESSAGEQUEUE_DEFAULT_TIMEOUT_SEC 10 -#define POSIX_MESSAGEQUEUE_DEFAULT_TIMEOUT_NSEC 0 - -#define POSIX_MESSAGEQUEUE_MAX_MESSAGE_SIZE 1024 -// note 10 is the default hard limit -#define POSIX_MESSAGEQUEUE_MAX_NB_MESSAGES 10 - -namespace Util -{ - -IMPL_DEBUG_MODULE( PosixMessageQueue, PosixMessageQueue, DEBUG_LEVEL_NORMAL ); - -PosixMessageQueue::PosixMessageQueue(std::string name) -: m_name( "/" + name ) -, m_blocking( eB_Blocking ) -, m_direction( eD_None ) -, m_owner( false ) -, m_handle( MQ_INVALID_ID ) -, m_tmp_buffer( NULL ) -, m_notifyHandler( NULL ) -, m_notifyHandlerLock( *(new PosixMutex()) ) -{ - m_timeout.tv_sec = POSIX_MESSAGEQUEUE_DEFAULT_TIMEOUT_SEC; - m_timeout.tv_nsec = POSIX_MESSAGEQUEUE_DEFAULT_TIMEOUT_NSEC; - - memset(&m_attr, 0, sizeof(m_attr)); - m_attr.mq_maxmsg = POSIX_MESSAGEQUEUE_MAX_NB_MESSAGES; - m_attr.mq_msgsize = POSIX_MESSAGEQUEUE_MAX_MESSAGE_SIZE; - m_tmp_buffer = new char[m_attr.mq_msgsize]; -} - -PosixMessageQueue::~PosixMessageQueue() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) PosixMessageQueue destroy\n", - this, m_name.c_str()); - Close(); - if(m_owner) { - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) unlink\n", - this, m_name.c_str()); - - if(mq_unlink(m_name.c_str()) == MQ_INVALID_ID) { - debugError("(%p, %s) could not unlink message queue: %s\n", - this, m_name.c_str(), strerror(errno)); - } - } - delete[] m_tmp_buffer; -} - -bool -PosixMessageQueue::doOpen(enum eDirection t, int flags, enum eBlocking b) -{ - - if(m_handle != MQ_INVALID_ID) { - debugError("(%p, %s) already open\n", - this, m_name.c_str()); - return false; - } - - switch(t) { - case eD_ReadOnly: flags |= O_RDONLY; break; - case eD_WriteOnly: flags |= O_WRONLY; break; - case eD_ReadWrite: flags |= O_RDWR; break; - default: - debugError("bad direction\n"); - return false; - } - - if(b == eB_NonBlocking) { - flags |= O_NONBLOCK; - } - - if(flags & O_CREAT) { - // only user has permissions - m_handle = mq_open(m_name.c_str(), flags, S_IRWXU, &m_attr); - } else { - - m_handle = mq_open(m_name.c_str(), flags); - } - if(m_handle == MQ_INVALID_ID) { - debugError("(%p, %s) could not open: %s\n", - this, m_name.c_str(), strerror(errno)); - return false; - } - if(flags & O_CREAT) { - m_owner = true; - } - if(mq_getattr(m_handle, &m_attr) == MQ_INVALID_ID) { - debugError("(%p, %s) could get attr: %s\n", - this, m_name.c_str(), strerror(errno)); - return false; - } - m_blocking = b; - return true; -} - -bool -PosixMessageQueue::Open(enum eDirection t, enum eBlocking b) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) open\n", - this, m_name.c_str()); - - if(m_handle != MQ_INVALID_ID) { - debugError("(%p, %s) already open\n", - this, m_name.c_str()); - return false; - } - return doOpen(t, 0, b); -} - -bool -PosixMessageQueue::Create(enum eDirection t, enum eBlocking b) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) create\n", - this, m_name.c_str()); - - if(m_handle != MQ_INVALID_ID) { - debugError("(%p, %s) already open\n", - this, m_name.c_str()); - return false; - } - return doOpen(t, O_CREAT | O_EXCL, b); -} - -bool -PosixMessageQueue::Close() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) close\n", - this, m_name.c_str()); - - if(m_handle == MQ_INVALID_ID) { - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) not open\n", - this, m_name.c_str()); - return true; - } - if(mq_close(m_handle)) { - debugError("(%p, %s) could not close: %s\n", - this, m_name.c_str(), strerror(errno)); - return false; - } - m_handle = MQ_INVALID_ID; - return true; -} - -enum PosixMessageQueue::eResult -PosixMessageQueue::Send(PosixMessageQueue::Message &m) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) send\n", - this, m_name.c_str()); - if(m_direction == eD_ReadOnly) { - debugError("Cannot write to read-only queue\n"); - return eR_Error; - } - - int len = m.getLength(); - if (len > m_attr.mq_msgsize) { - debugError("Message too long\n"); - return eR_Error; - } - - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec += m_timeout.tv_sec; - timeout.tv_nsec += m_timeout.tv_nsec; - if(timeout.tv_nsec >= 1000000000LL) { - timeout.tv_sec++; - timeout.tv_nsec -= 1000000000LL; - } - - if(!m.serialize(m_tmp_buffer)) { - debugError("Could not serialize\n"); - return eR_Error; - } - - if(mq_timedsend(m_handle, m_tmp_buffer, len, m.getPriority(), &timeout) == MQ_INVALID_ID) { - switch(errno) { - case EAGAIN: - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) full\n", - this, m_name.c_str()); - return eR_Again; - case ETIMEDOUT: - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) read timed out\n", - this, m_name.c_str()); - return eR_Timeout; - default: - debugError("(%p, %s) could not send: %s\n", - this, m_name.c_str(), strerror(errno)); - return eR_Error; - } - } - return eR_OK; -} - -enum PosixMessageQueue::eResult -PosixMessageQueue::Receive(PosixMessageQueue::Message &m) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) receive\n", - this, m_name.c_str()); - if(m_direction == eD_WriteOnly) { - debugError("Cannot read from write-only queue\n"); - return eR_Error; - } - - struct timespec timeout; - clock_gettime(CLOCK_REALTIME, &timeout); - timeout.tv_sec += m_timeout.tv_sec; - timeout.tv_nsec += m_timeout.tv_nsec; - if(timeout.tv_nsec >= 1000000000LL) { - timeout.tv_sec++; - timeout.tv_nsec -= 1000000000LL; - } - - signed int len; - unsigned prio; - if((len = mq_timedreceive(m_handle, m_tmp_buffer, m_attr.mq_msgsize, &prio, &timeout)) < 0) { - switch(errno) { - case EAGAIN: - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) empty\n", - this, m_name.c_str()); - return eR_Again; - case ETIMEDOUT: - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) read timed out\n", - this, m_name.c_str()); - return eR_Timeout; - default: - debugError("(%p, %s) could not receive: %s\n", - this, m_name.c_str(), strerror(errno)); - return eR_Error; - } - } - - if(!m.deserialize(m_tmp_buffer, len, prio)) { - debugError("Could not parse message\n"); - return eR_Error; - } - return eR_OK; -} - - -int -PosixMessageQueue::countMessages() -{ - if(m_handle == MQ_INVALID_ID) { - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) invalid handle\n", - this, m_name.c_str()); - return -1; - } - struct mq_attr attr; - if(mq_getattr(m_handle, &attr) == MQ_INVALID_ID) { - debugError("(%p, %s) could get attr: %s\n", - this, m_name.c_str(), strerror(errno)); - return -1; - } - return attr.mq_curmsgs; -} - -bool -PosixMessageQueue::canSend() -{ - return countMessages() < m_attr.mq_maxmsg; -} - -bool -PosixMessageQueue::canReceive() -{ - return countMessages() > 0; -} - -bool -PosixMessageQueue::setNotificationHandler(Util::Functor *f) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) setting handler to %p\n", - this, m_name.c_str(), f); - - // ensure we don't change the notifier while - // it's used - MutexLockHelper lock(m_notifyHandlerLock); - if(m_notifyHandler == NULL) { - m_notifyHandler = f; - return true; - } else { - debugError("handler already present\n"); - return false; - } -} - -bool -PosixMessageQueue::unsetNotificationHandler() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) unsetting handler\n", - this, m_name.c_str()); - - // ensure we don't change the notifier while - // it's used - MutexLockHelper lock(m_notifyHandlerLock); - if(m_notifyHandler != NULL) { - m_notifyHandler = NULL; - return true; - } else { - debugWarning("no handler present\n"); - return true; // not considered an error - } -} - -void -PosixMessageQueue::notifyCallback() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) Notified\n", - this, m_name.c_str()); - // make sure the handler is not changed - MutexLockHelper lock(m_notifyHandlerLock); - if(m_notifyHandler) { - (*m_notifyHandler)(); - } -} - -bool -PosixMessageQueue::enableNotification() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) set\n", - this, m_name.c_str()); - - sigevent evp; - memset (&evp, 0, sizeof(evp)); - evp.sigev_notify = SIGEV_THREAD; - evp.sigev_value.sival_ptr = (void *)this; - evp.sigev_notify_function = ¬ifyCallbackStatic; - - if(mq_notify(m_handle, &evp) == MQ_INVALID_ID) { - debugError("(%p, %s) could set notifier: %s\n", - this, m_name.c_str(), strerror(errno)); - return false; - } - return true; -} - -bool -PosixMessageQueue::disableNotification() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) unset\n", - this, m_name.c_str()); - - if(mq_notify(m_handle, NULL) == MQ_INVALID_ID) { - debugError("(%p, %s) could unset notifier: %s\n", - this, m_name.c_str(), strerror(errno)); - return false; - } - return true; -} - -void -PosixMessageQueue::show() -{ - debugOutput(DEBUG_LEVEL_NORMAL, "(%p) MessageQueue %s\n", this, m_name.c_str()); -} - -void -PosixMessageQueue::setVerboseLevel(int i) -{ - setDebugLevel(i); - m_notifyHandlerLock.setVerboseLevel(i); -} - -} // end of namespace Index: /anches/libffado-2.0/src/libutil/DelayLockedLoop.h =================================================================== --- /branches/libffado-2.0/src/libutil/DelayLockedLoop.h (revision 864) +++ (revision ) @@ -1,67 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __FFADO_DELAYLOCKEDLOOP__ -#define __FFADO_DELAYLOCKEDLOOP__ - -namespace Util { - -class DelayLockedLoop { - -public: - - DelayLockedLoop(unsigned int order, float *coeffs); - DelayLockedLoop(unsigned int order); - DelayLockedLoop(); - - virtual ~DelayLockedLoop(); - - float getCoefficient(unsigned int i); - void setCoefficient(unsigned int i, float c); - - void setIntegrator(unsigned int i, float c); - - void reset(); - - unsigned int getOrder(); - void setOrder(unsigned int i); - void setOrder(unsigned int order, float* coeffs); - - void put(float v); - float get(); - float getError(); - -protected: - - unsigned int m_order; - - float *m_coeffs; - float *m_nodes; - float m_error; -}; - -} // end of namespace FFADOUtil - -#endif /* __FFADO_DELAYLOCKEDLOOP__ */ - - Index: /anches/libffado-2.0/src/libutil/IpcRingBuffer.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/IpcRingBuffer.cpp (revision 1172) +++ (revision ) @@ -1,574 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "IpcRingBuffer.h" -#include "PosixMessageQueue.h" -#include "PosixSharedMemory.h" -#include "Mutex.h" -#include "PosixMutex.h" -#include "Functors.h" - -// FIXME: if we restrict the nb_blocks to a power of two, the overflows -// can be implemented using masks - -namespace Util { - -IMPL_DEBUG_MODULE( IpcRingBuffer, IpcRingBuffer, DEBUG_LEVEL_VERBOSE ); - -IpcRingBuffer::IpcRingBuffer(std::string name, - enum eBufferType type, - enum eDirection dir, - enum eBlocking blocking, - unsigned int blocks, unsigned int block_size) -: m_name(name) -, m_blocks(blocks) -, m_blocksize(block_size) -, m_type( type ) -, m_direction( dir ) -, m_blocking( blocking ) -, m_initialized( false ) -, m_next_block( 1 ) -, m_last_block_ack( 0 ) -, m_idx( 1 ) -, m_last_idx_ack( 0 ) -, m_ping_queue( *(new PosixMessageQueue(name+":ping")) ) -, m_pong_queue( *(new PosixMessageQueue(name+":pong")) ) -, m_memblock( *(new PosixSharedMemory(name+":mem", blocks*block_size)) ) -, m_access_lock( *(new PosixMutex()) ) -, m_notify_functor( *(new MemberFunctor0< IpcRingBuffer*, void (IpcRingBuffer::*)() > - ( this, &IpcRingBuffer::notificationHandler, false )) ) -, m_block_requested_for_read( false ) -, m_block_requested_for_write( false ) -{ - m_ping_queue.setVerboseLevel(getDebugLevel()); - m_pong_queue.setVerboseLevel(getDebugLevel()); - m_memblock.setVerboseLevel(getDebugLevel()); - m_access_lock.setVerboseLevel(getDebugLevel()); - sem_init(&m_activity, 0, 0); -} - -IpcRingBuffer::~IpcRingBuffer() -{ - // make sure everyone is done with this - // should not be necessary AFAIK - m_access_lock.Lock(); - m_initialized=false; - delete &m_memblock; - delete &m_ping_queue; - delete &m_pong_queue; - m_access_lock.Unlock(); - - delete &m_access_lock; - delete &m_notify_functor; - sem_destroy(&m_activity); -} - -bool -IpcRingBuffer::init() -{ - if(m_initialized) { - debugError("(%p, %s) Already initialized\n", - this, m_name.c_str()); - return false; - } - - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) init %s\n", this, m_name.c_str()); - switch(m_type) { - case eBT_Master: - // a master creates and owns all of the shared memory structures - // for outward connections we write the data, else we read - if(!m_memblock.Create( PosixSharedMemory::eD_ReadWrite )) - { - debugError("(%p, %s) Could not create memblock\n", - this, m_name.c_str()); - return false; - } - - m_memblock.LockInMemory(true); - // for outward connections we do the pinging, else - // we do the pong-ing. note that for writing, we open read-write - // in order to be able to dequeue when the queue is full - if(!m_ping_queue.Create( (m_direction == eD_Outward ? - PosixMessageQueue::eD_ReadWrite : - PosixMessageQueue::eD_ReadOnly), - (m_blocking==eB_Blocking ? - PosixMessageQueue::eB_Blocking : - PosixMessageQueue::eB_NonBlocking) - )) - { - debugError("(%p, %s) Could not create ping queue\n", - this, m_name.c_str()); - return false; - } - if(!m_pong_queue.Create( (m_direction == eD_Outward ? - PosixMessageQueue::eD_ReadOnly : - PosixMessageQueue::eD_ReadWrite), - (m_blocking==eB_Blocking ? - PosixMessageQueue::eB_Blocking : - PosixMessageQueue::eB_NonBlocking) - )) - { - debugError("(%p, %s) Could not create pong queue\n", - this, m_name.c_str()); - return false; - } - break; - case eBT_Slave: - // a slave only opens the shared memory structures - // for outward connections we write the data, else we read - if(!m_memblock.Open( (m_direction == eD_Outward - ? PosixSharedMemory::eD_ReadWrite - : PosixSharedMemory::eD_ReadOnly) )) - { - debugError("(%p, %s) Could not open memblock\n", - this, m_name.c_str()); - return false; - } - m_memblock.LockInMemory(true); - // for outward connections we do the pinging, else - // we do the pong-ing. note that for writing, we open read-write - // in order to be able to dequeue when the queue is full - if(!m_ping_queue.Open( (m_direction == eD_Outward ? - PosixMessageQueue::eD_ReadWrite : - PosixMessageQueue::eD_ReadOnly), - (m_blocking==eB_Blocking ? - PosixMessageQueue::eB_Blocking : - PosixMessageQueue::eB_NonBlocking) - )) - { - debugError("(%p, %s) Could not open ping queue\n", - this, m_name.c_str()); - return false; - } - if(!m_pong_queue.Open( (m_direction == eD_Outward ? - PosixMessageQueue::eD_ReadOnly : - PosixMessageQueue::eD_ReadWrite), - (m_blocking==eB_Blocking ? - PosixMessageQueue::eB_Blocking : - PosixMessageQueue::eB_NonBlocking) - )) - { - debugError("(%p, %s) Could not open pong queue\n", - this, m_name.c_str()); - return false; - } - break; - } - - // if we are on the sending end of the buffer, we need a notifier - // on the pong queue - // the receiving end is driven by the messages in the ping queue - if(m_direction == eD_Outward) { - if(!m_pong_queue.setNotificationHandler(&m_notify_functor)) { - debugError("Could not set Notification Handler\n"); - return false; - } - // enable the handler - if(!m_pong_queue.enableNotification()) { - debugError("Could not enable notification\n"); - } - } - - m_initialized = true; - return true; -} - -void -IpcRingBuffer::notificationHandler() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) IpcRingBuffer %s\n", this, m_name.c_str()); - // prevent multiple access - MutexLockHelper lock(m_access_lock); - - // The first thing we do is re-enable the handler - // it is not going to be called since there are messages in the queue - // first enabling the handler, then reading all received messages will - // ensure that we either read or get notified of any message that arrives - // while this handler is running - if(!m_pong_queue.enableNotification()) { - debugError("Could not re-enable notification\n"); - } - - // no need for a lock protecting the pong queue as long as we are the only ones reading it - // while we have messages to read, read them - while(m_pong_queue.canReceive()) { - // message placeholder - IpcMessage m_ack = IpcMessage(); // FIXME: stack allocation not strictly RT safe - // read ping message (blocks) - enum PosixMessageQueue::eResult msg_res; - msg_res = m_pong_queue.Receive(m_ack); - switch(msg_res) { - case PosixMessageQueue::eR_OK: - break; - default: // we were just notified, anything except OK is an error - debugError("Could not read from ping queue\n"); - } - - IpcMessage::eMessageType type = m_ack.getType(); - if(type == IpcMessage::eMT_DataAck) { - // get a view on the data - struct DataWrittenMessage* data = reinterpret_cast(m_ack.getDataPtr()); - - debugOutput(DEBUG_LEVEL_VERBOSE, "Received ack idx %d at id %d\n", data->idx, data->id); - - // check counters - unsigned int expected_block_ack = m_last_block_ack+1; - if(expected_block_ack == m_blocks) expected_block_ack = 0; - if(data->id != expected_block_ack) { - debugWarning("unexpected block id: %d (expected %d)\n", data->id, expected_block_ack); - } - - unsigned int expected_block_idx = m_last_idx_ack+1; //will auto-overflow - if(data->idx != expected_block_idx) { - debugWarning("unexpected block idx: %d (expected %d)\n", data->idx, expected_block_idx); - } - - // prepare the next expected values - // this is the only value used (and written in case of error) in the other thread - m_last_block_ack = data->id; - // this is not used - m_last_idx_ack = data->idx; - // signal activity - if(m_blocking == eB_Blocking) { - sem_post(&m_activity); - } - } else { - debugError("Invalid message received (type %d)\n", type); - } - } -} - -unsigned int -IpcRingBuffer::getBufferFill() -{ - // the next pointer is last_written+1 - // so the bufferfill = last_written - last_ack - // = last_written+1 - last_ack - 1 - // last_ack is always <= last_written. if not, - // last_written has wrapped - // => wrap if: last_written < last_ack - // or last_written+1 < last_ack+1 - // or m_next_block < last_ack+1 - // unwrap if this happens - int bufferfill = m_next_block - m_last_block_ack - 1; - if(m_next_block <= m_last_block_ack) { - bufferfill += m_blocks; - } - assert(bufferfill>=0); - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) fill: %d\n", this, m_name.c_str(), bufferfill); - return (unsigned int)bufferfill; -} - - -enum IpcRingBuffer::eResult -IpcRingBuffer::requestBlockForWrite(void **block) -{ - if(m_block_requested_for_write) { - debugError("Already a block requested for write\n"); - return eR_Error; - } - - // check if we can write a message - // we can send when: - // - we are not overwriting - // AND - we are in blocking mode and - // - OR (we are in non-blocking mode and there is space) - - if(m_blocking == eB_Blocking) { - if(getBufferFill() >= m_blocks) { - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) full\n", this, m_name.c_str()); - // make it wait - sem_wait(&m_activity); - } - } else { - // there are no free data blocks, or there is no message space - if(getBufferFill() >= m_blocks || !m_ping_queue.canSend()) { - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) full\n", this, m_name.c_str()); - return eR_Again; - } - } - - // check for overflow - if(m_next_block == m_last_block_ack) { - debugWarning("Overwriting not yet read block %u\n", m_next_block); - // we have to increment the block_read pointer - // in order to keep consistency - m_last_block_ack++; - if(m_last_block_ack == m_blocks) { - m_last_block_ack = 0; - } - } - - int offset = m_next_block * m_blocksize; - *block = m_memblock.requestBlock(offset, m_blocksize); - if(*block) { - m_block_requested_for_write = true; - return eR_OK; - } else { - return eR_Error; - } -} - -enum IpcRingBuffer::eResult -IpcRingBuffer::releaseBlockForWrite() -{ - if(!m_block_requested_for_write) { - debugError("No block requested for write\n"); - return eR_Error; - } - - IpcMessage &m = m_LastDataMessageSent; - - // prepare ping message - m.setType(IpcMessage::eMT_DataWritten); - m.setDataSize(sizeof(struct DataWrittenMessage)); - - // get a view on the data - struct DataWrittenMessage* data = reinterpret_cast(m.getDataPtr()); - // set the data contents - data->id = m_next_block; - data->idx = m_idx; - - debugOutput(DEBUG_LEVEL_VERBOSE, "Releasing block idx %d at id %d\n", data->idx, data->id); - - // send ping message - enum PosixMessageQueue::eResult msg_res; - msg_res = m_ping_queue.Send(m); - switch(msg_res) { - case PosixMessageQueue::eR_OK: - break; - case PosixMessageQueue::eR_Again: - // this is a bug since we checked whether it was empty or not - debugError("Bad response value\n"); - m_block_requested_for_write = false; - return eR_Error; - case PosixMessageQueue::eR_Timeout: - debugOutput(DEBUG_LEVEL_VERBOSE, "Timeout\n"); - m_block_requested_for_write = false; - return eR_Timeout; // blocking and no space on time - default: - debugError("Could not send to ping queue\n"); - m_block_requested_for_write = false; - return eR_Error; - } - - // increment and wrap - m_next_block++; - if(m_next_block == m_blocks) { - m_next_block = 0; - } - m_idx++; - m_block_requested_for_write = false; - return eR_OK; -} - -enum IpcRingBuffer::eResult -IpcRingBuffer::Write(char *block) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) IpcRingBuffer\n", this, m_name.c_str()); - if(m_direction == eD_Inward) { - debugError("Cannot write to inbound buffer\n"); - return eR_Error; - } - - enum IpcRingBuffer::eResult msg_res; - void *xmit_block; - // request a block for reading - msg_res = requestBlockForWrite(&xmit_block); - if(msg_res == eR_OK) { - // if we receive a eR_OK, we should always be able to write to the shared memory - memcpy(xmit_block, block, m_blocksize); - releaseBlockForWrite(); - } - return msg_res; -} - -enum IpcRingBuffer::eResult -IpcRingBuffer::requestBlockForRead(void **block) -{ - if(m_block_requested_for_read) { - debugError("Already a block requested for read\n"); - return eR_Error; - } - // message placeholder - IpcMessage &m = m_LastDataMessageReceived; - - // read ping message (blocks) - enum PosixMessageQueue::eResult msg_res; - msg_res = m_ping_queue.Receive(m); - switch(msg_res) { - case PosixMessageQueue::eR_OK: - break; - case PosixMessageQueue::eR_Again: - return eR_Again; // non-blocking and no message - case PosixMessageQueue::eR_Timeout: - debugOutput(DEBUG_LEVEL_VERBOSE, "Timeout\n"); - return eR_Timeout; // blocking and no message on time - default: - debugError("Could not read from ping queue\n"); - return eR_Error; - } - - IpcMessage::eMessageType type = m.getType(); - if(type == IpcMessage::eMT_DataWritten) { - // get a view on the data - struct DataWrittenMessage* data = reinterpret_cast(m.getDataPtr()); - debugOutput(DEBUG_LEVEL_VERBOSE, "Requested block idx %d at id %d\n", data->idx, data->id); - - // check counters - if(data->id != m_next_block) { - debugWarning("unexpected block id: %d (expected %d)\n", data->id, m_next_block); - } - if(data->idx != m_idx) { - debugWarning("unexpected block idx: %d (expected %d)\n", data->idx, m_idx); - } - - int offset = data->id * m_blocksize; - *block = m_memblock.requestBlock(offset, m_blocksize); - if(*block) { - m_block_requested_for_read = true; - return eR_OK; - } else { - return eR_Error; - } - } else { - debugError("Invalid message received (type %d)\n", type); - return eR_Error; - } -} - -enum IpcRingBuffer::eResult -IpcRingBuffer::releaseBlockForRead() -{ - if(!m_block_requested_for_read) { - debugError("No block requested for read\n"); - return eR_Error; - } - - IpcMessage &m = m_LastDataMessageReceived; - - // get a view on the data - struct DataWrittenMessage* data = reinterpret_cast(m.getDataPtr()); - debugOutput(DEBUG_LEVEL_VERBOSE, "Releasing block idx %d at id %d\n", data->idx, data->id); - - // write a response to the pong queue - // reuse the message - m.setType(IpcMessage::eMT_DataAck); - enum PosixMessageQueue::eResult msg_res; - msg_res = m_pong_queue.Send(m); - switch(msg_res) { - case PosixMessageQueue::eR_OK: - break; - case PosixMessageQueue::eR_Again: - debugOutput(DEBUG_LEVEL_VERBOSE, "Again on ACK\n"); -// return eR_Again; // non-blocking and no message - case PosixMessageQueue::eR_Timeout: - debugOutput(DEBUG_LEVEL_VERBOSE, "Timeout on ACK\n"); -// return eR_Timeout; // blocking and no message on time - default: - debugError("Could not write to pong queue\n"); - m_block_requested_for_read = false; - return eR_Error; - } - - // prepare the next expected values - m_next_block = data->id + 1; - if(m_next_block == m_blocks) { - m_next_block = 0; - } - m_idx = data->idx + 1; - m_block_requested_for_read = false; - return eR_OK; -} - -enum IpcRingBuffer::eResult -IpcRingBuffer::Read(char *block) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) IpcRingBuffer %s\n", this, m_name.c_str()); - if(m_direction == eD_Outward) { - debugError("Cannot read from outward buffer\n"); - return eR_Error; - } - - enum IpcRingBuffer::eResult msg_res; - void *rcv_block; - // request a block for reading - msg_res = requestBlockForRead(&rcv_block); - if(msg_res == eR_OK) { - // if we receive a eR_OK, we should always be able to read the shared memory - memcpy(block, rcv_block, m_blocksize); - releaseBlockForRead(); - } - return msg_res; -} - -void -IpcRingBuffer::show() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) IpcRingBuffer %s\n", this, m_name.c_str()); -} - -void -IpcRingBuffer::setVerboseLevel(int i) -{ - setDebugLevel(i); - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) verbose: %d\n", this, m_name.c_str(), i); - m_ping_queue.setVerboseLevel(i); - m_pong_queue.setVerboseLevel(i); - m_memblock.setVerboseLevel(i); - m_access_lock.setVerboseLevel(i); -} - -bool -IpcRingBuffer::IpcMessage::serialize(char *buff) -{ - memcpy(buff, &m_header, sizeof(m_header)); - buff += sizeof(m_header); - memcpy(buff, m_data, m_data_len); - return true; -} -bool -IpcRingBuffer::IpcMessage::deserialize(const char *buff, unsigned int length, unsigned prio) -{ - assert(length >= sizeof(m_header)); - memcpy(&m_header, buff, sizeof(m_header)); - - if(m_header.magic != FFADO_IPC_RINGBUFFER_MAGIC) { - return false; // invalid magic - } - if(m_header.version != FFADO_IPC_RINGBUFFER_VERSION) { - return false; // invalid version - } - - m_data_len = length - sizeof(m_header); - buff += sizeof(m_header); - - assert(m_data_len <= FFADO_IPC_MAX_MESSAGE_SIZE); - memcpy(m_data, buff, m_data_len); - - m_priority = prio; - return true; -} - - -} // Util Index: /anches/libffado-2.0/src/libutil/PosixSharedMemory.h =================================================================== --- /branches/libffado-2.0/src/libutil/PosixSharedMemory.h (revision 1172) +++ (revision ) @@ -1,90 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __UTIL_POSIX_SHARED_MEMORY__ -#define __UTIL_POSIX_SHARED_MEMORY__ - -#include "debugmodule/debugmodule.h" - -#include - -namespace Util { - -/** - * @brief A POSIX Shared Memory Wrapper. - */ - -class PosixSharedMemory -{ -public: - enum eDirection { - eD_None, - eD_ReadOnly, - eD_WriteOnly, - eD_ReadWrite - }; - - enum eResult { - eR_OK, - eR_Again, - eR_Error, - }; - -public: - PosixSharedMemory(std::string name, unsigned int len); - virtual ~PosixSharedMemory(); - - // mlock interface - /** - * Tries to (un)lock the segment to stay in memory - * @param lock - * @return - */ - bool LockInMemory(bool lock); - - virtual bool Create(enum eDirection d=eD_ReadWrite); - virtual bool Open(enum eDirection d=eD_ReadWrite); - virtual bool Close(); - - virtual enum eResult Write(unsigned int offset, void * buff, unsigned int len); - virtual enum eResult Read(unsigned int offset, void * buff, unsigned int len); - - virtual void* requestBlock(unsigned int offset, unsigned int len); - virtual void commitBlock(unsigned int offset, unsigned int len); - - virtual void show(); - virtual void setVerboseLevel(int l) {setDebugLevel(l);}; - -protected: - DECLARE_DEBUG_MODULE; - -private: - std::string m_name; - unsigned int m_size; - bool m_owner; - char * m_access; -}; - -} // namespace Util - -#endif // __UTIL__POSIX_SHARED_MEMORY__ Index: /anches/libffado-2.0/src/libutil/test-dll.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/test-dll.cpp (revision 864) +++ (revision ) @@ -1,124 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "DelayLockedLoop.h" -#include - -using namespace Util; - -int main() { - int i=0; - int i2=0; - - #define MAX_TEST_ORDER 2 - - #define NB_VALUES 12 - #define NB_LOOPS 50000 - - // this test is for a second order loop, - - - float omega=6.28*0.001; - float coeffs[MAX_TEST_ORDER]; - coeffs[0]=1.41*omega; - coeffs[1]=omega*omega; - - DelayLockedLoop d1(1, coeffs); - - DelayLockedLoop d2(2, coeffs); - - // this sequence represents the average deviation of the sample period - float deviation[NB_VALUES]={-0.001, 0.0, 0.001, 0.001, -0.001, 0.001, -0.001, 0.001, -0.001, 0.00, 0.001, -0.001}; - float average=0.0; - - // these are the actual period times - float ideal_values[NB_LOOPS]; - float actual_values[NB_LOOPS]; - float actual_values2[NB_LOOPS]; - - // we define a nominal sample time: - float ts_nominal=1.0/48000.0; - float period=100.0; - - // we calculate the deviated sample times - for (i=0;i. - * - */ - -#ifndef __FFADO_PACKETBUFFER__ -#define __FFADO_PACKETBUFFER__ - -#include "../debugmodule/debugmodule.h" -#include -#include "libutil/ringbuffer.h" - -namespace Streaming { - -class PacketBuffer { -// note: all sizes in quadlets -public: - - PacketBuffer(int headersize, int buffersize, int max_packetsize) - : m_headersize(headersize), m_buffersize(buffersize), m_max_packetsize(max_packetsize), - payload_buffer(0), header_buffer(0), len_buffer(0) - {}; - - virtual ~PacketBuffer(); - void setVerboseLevel(int l) { setDebugLevel( l ); }; - - int initialize(); - - void flush(); - - int addPacket(quadlet_t *packet, int packet_len); - - int getNextPacket(quadlet_t *packet, int packet_len); - int getBufferFillPackets(); - int getBufferFillPayload(); - -protected: - int m_headersize; - int m_buffersize; - int m_max_packetsize; - - ffado_ringbuffer_t *payload_buffer; - ffado_ringbuffer_t *header_buffer; - ffado_ringbuffer_t *len_buffer; - - DECLARE_DEBUG_MODULE; - -}; - -} - -#endif /* __FFADO_PACKETBUFFER__ */ - - Index: /anches/libffado-2.0/src/libutil/DelayLockedLoop.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/DelayLockedLoop.cpp (revision 864) +++ (revision ) @@ -1,301 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "DelayLockedLoop.h" - -namespace Util { - -/** - * Creates a new Delay Locked Loop with a predefined order and - * a predefined set of coefficients. - * - * Make sure coeffs is a float array containing order+1 coefficients. - * - * @pre order > 0 - * @param order order of the DLL - * @param coeffs coefficients to use - */ -DelayLockedLoop::DelayLockedLoop(unsigned int order, float *coeffs) -{ - unsigned int i; - - m_order=order; - if (m_order==0) m_order=1; - - m_coeffs=new float[order]; - m_nodes=new float[order]; - - for (i=0;i 0 - * @param order order of the DLL - */ -DelayLockedLoop::DelayLockedLoop(unsigned int order) -{ - unsigned int i; - - m_order=order; - if (m_order==0) m_order=1; - - m_coeffs=new float[order]; - m_nodes=new float[order]; - - for (i=0;i 0 - * @param order new order for the DLL - * @param coeffs coefficients to use - */ -void -DelayLockedLoop::setOrder(unsigned int order, float* coeffs) { - unsigned int i; - - reset(); - - m_order=order; - if (m_order==0) m_order=1; - - if(m_coeffs) delete[] m_coeffs; - m_coeffs=new float[order]; - - if(m_nodes) delete[] m_nodes; - m_nodes=new float[order]; - - for (i=0;i 0 - * @param order new order for the DLL - */ -void -DelayLockedLoop::setOrder(unsigned int order) { - unsigned int i; - - reset(); - - m_order=order; - - if (m_order==0) m_order=1; - - if(m_coeffs) delete[] m_coeffs; - m_coeffs=new float[order]; - - if(m_nodes) delete[] m_nodes; - m_nodes=new float[order]; - - for (i=0;i. - * - */ - -#ifndef __UTIL_POSIX_MESSAGE_QUEUE__ -#define __UTIL_POSIX_MESSAGE_QUEUE__ - -#include "debugmodule/debugmodule.h" - -#define _XOPEN_SOURCE 600 -#include -#include -#include - -namespace Util -{ - -class Functor; -class Mutex; - -/** - * @brief A POSIX Message Queue Wrapper. - */ - -class PosixMessageQueue -{ -public: - class Message { - public: - Message() {}; - virtual ~Message() {}; - - virtual unsigned getPriority() = 0; - - virtual unsigned int getLength() = 0; - virtual bool serialize(char *buff) = 0; - virtual bool deserialize(const char *buff, unsigned int length, unsigned prio) = 0; - }; - -public: - enum eDirection { - eD_None, - eD_ReadOnly, - eD_WriteOnly, - eD_ReadWrite - }; - - enum eResult { - eR_OK, - eR_Again, - eR_Error, - eR_Timeout, - }; - - // blocking mode - enum eBlocking { - eB_Blocking, - eB_NonBlocking, - }; - -public: - PosixMessageQueue(std::string name); - virtual ~PosixMessageQueue(); - - virtual bool Open(enum eDirection, enum eBlocking blocking = eB_Blocking); - virtual bool Create(enum eDirection, enum eBlocking blocking = eB_Blocking); - virtual bool Close(); - - virtual enum eResult Send(Message &m); - virtual enum eResult Receive(Message &m); - - virtual int countMessages(); - virtual bool canSend(); - virtual bool canReceive(); - - virtual bool setNotificationHandler(Util::Functor *f); - virtual bool unsetNotificationHandler(); - virtual bool enableNotification(); - virtual bool disableNotification(); - - virtual unsigned int getMaxMessageLength() - {return m_attr.mq_msgsize;}; - - virtual void show(); - virtual void setVerboseLevel(int l); - -private: - bool doOpen(enum eDirection t, int, enum eBlocking); - static void notifyCallbackStatic(sigval_t t) { - PosixMessageQueue *obj; - obj = static_cast(t.sival_ptr); - obj->notifyCallback(); - } - void notifyCallback(); - -protected: - DECLARE_DEBUG_MODULE; - -private: - std::string m_name; - enum eBlocking m_blocking; - enum eDirection m_direction; - bool m_owner; - struct timespec m_timeout; - - mqd_t m_handle; - struct mq_attr m_attr; - char * m_tmp_buffer; - Util::Functor * m_notifyHandler; - Util::Mutex& m_notifyHandlerLock; -}; - -} // end of namespace - -#endif // __UTIL_POSIX_MESSAGE_QUEUE__ Index: /anches/libffado-2.0/src/libutil/PosixSharedMemory.cpp =================================================================== --- /branches/libffado-2.0/src/libutil/PosixSharedMemory.cpp (revision 1172) +++ (revision ) @@ -1,285 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "PosixSharedMemory.h" - -#include -#include -#include -#include - -namespace Util { - -IMPL_DEBUG_MODULE( PosixSharedMemory, PosixSharedMemory, DEBUG_LEVEL_NORMAL ); - -PosixSharedMemory::PosixSharedMemory(std::string name, unsigned int size) -: m_name( "/" + name ) -, m_size( size ) -, m_owner( false ) -, m_access( NULL ) -{ - -} - -PosixSharedMemory::~PosixSharedMemory() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) destroy\n", - this, m_name.c_str()); - Close(); - if(m_owner) { - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) unlink\n", - this, m_name.c_str()); - shm_unlink(m_name.c_str()); - } -} - -bool -PosixSharedMemory::Open(enum eDirection d) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) open\n", - this, m_name.c_str()); - if(m_access != NULL) { - debugError("(%p, %s) already attached to segment\n", this, m_name.c_str()); - } - - int flags=0; - switch(d) { - case eD_ReadOnly: flags |= O_RDONLY; break; - case eD_WriteOnly: flags |= O_WRONLY; break; - case eD_ReadWrite: flags |= O_RDWR; break; - default: - debugError("bad direction\n"); - return false; - } - - // open the shared memory segment - int fd = shm_open(m_name.c_str(), flags, S_IRWXU); - if (fd < 0) { - if (errno != ENOENT) { - debugError("(%p, %s) Cannot open shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - } else { - debugError("(%p, %s) shared memory segment does not exist: %s\n", - this, m_name.c_str(), strerror (errno)); - } - close(fd); - return false; - } - - // mmap the memory - flags=0; - switch(d) { - case eD_ReadOnly: flags |= PROT_READ; break; - case eD_WriteOnly: flags |= PROT_WRITE; break; - case eD_ReadWrite: flags |= PROT_READ|PROT_WRITE; break; - default: - debugError("bad direction\n"); - shm_unlink(m_name.c_str()); - return false; - } - - m_access = (char*)mmap(0, m_size, flags, MAP_SHARED, fd, 0); - if (m_access == MAP_FAILED) { - debugError("(%p, %s) Cannot mmap shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - close(fd); - m_access = NULL; - shm_unlink(m_name.c_str()); - return false; - } - - // close the fd - close(fd); - return true; -} - -bool -PosixSharedMemory::Create(enum eDirection d) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) create dir: %d, size: %u \n", - this, m_name.c_str(), d, m_size); - if(m_access != NULL) { - debugError("(%p, %s) already attached to segment\n", this, m_name.c_str()); - } - - // open the shared memory segment - // always create it readwrite, if not, the other side can't map - // it correctly, nor can we truncate it to the right length. - int fd = shm_open(m_name.c_str(), O_RDWR|O_CREAT, S_IRWXU); - if (fd < 0) { - debugError("(%p, %s) Cannot open shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - close(fd); - return false; - } - - // set size - if (ftruncate (fd, m_size) < 0) { - debugError("(%p, %s) Cannot set shared memory size: %s\n", - this, m_name.c_str(), strerror (errno)); - close(fd); - return false; - } - - // mmap the memory - int flags=0; - switch(d) { - case eD_ReadOnly: flags |= PROT_READ; break; - case eD_WriteOnly: flags |= PROT_WRITE; break; - case eD_ReadWrite: flags |= PROT_READ|PROT_WRITE; break; - default: - debugError("bad direction\n"); - return false; - } - - m_access = (char*)mmap(0, m_size, flags, MAP_SHARED, fd, 0); - if (m_access == MAP_FAILED) { - debugError("(%p, %s) Cannot mmap shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - close(fd); - m_access = NULL; - return false; - } - - // close the fd - close(fd); - - m_owner = true; - return true; -} - -bool -PosixSharedMemory::Close() -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) close\n", - this, m_name.c_str()); - if(m_access) { - if(munmap(m_access, m_size)) { - debugError("(%p, %s) Cannot munmap shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - return false; - } - m_access = NULL; - } else { - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) not open\n", - this, m_name.c_str()); - } - return true; -} - -enum PosixSharedMemory::eResult -PosixSharedMemory::Write(unsigned int offset, void * buff, unsigned int len) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) write\n", - this, m_name.c_str()); - if(offset+len <= m_size) { - char * addr = m_access + offset; - memcpy(addr, buff, len); - // if(msync(addr, len, MS_SYNC | MS_INVALIDATE)) { - // debugError("Could not sync written block\n"); - // return eR_Error; - // } - return eR_OK; - } else { - debugError("Requested block (%u) out of range (%u)\n", offset+len, m_size); - return eR_Error; - } -} - -enum PosixSharedMemory::eResult -PosixSharedMemory::Read(unsigned int offset, void * buff, unsigned int len) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) read\n", - this, m_name.c_str()); - if(offset+len <= m_size) { - char * addr = m_access + offset; - memcpy(buff, addr, len); - return eR_OK; - } else { - debugError("Requested block (%u) out of range (%u)\n", offset+len, m_size); - return eR_Error; - } -} - -void* -PosixSharedMemory::requestBlock(unsigned int offset, unsigned int len) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) getBlock\n", - this, m_name.c_str()); - if(offset+len <= m_size) { - return (void*)(m_access + offset); - } else { - debugError("Requested block (%u) out of range (%u)\n", offset+len, m_size); - return NULL; - } -} - -void -PosixSharedMemory::commitBlock(unsigned int offset, unsigned int len) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) commitBlock\n", - this, m_name.c_str()); - if(offset+len >= m_size) { - debugError("Committed block (%u) out of range (%u)\n", offset+len, m_size); - } -} - -bool -PosixSharedMemory::LockInMemory(bool lock) -{ - debugOutput(DEBUG_LEVEL_VERBOSE, - "(%p, %s) LockInMemory\n", - this, m_name.c_str()); - if(lock) { - if(mlock(m_access, m_size)) { - debugError("(%p, %s) Cannot mlock shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - return false; - } else return true; - } else { - if(munlock(m_access, m_size)) { - debugError("(%p, %s) Cannot munlock shared memory: %s\n", - this, m_name.c_str(), strerror (errno)); - return false; - } else return true; - } - return false; -} - -void -PosixSharedMemory::show() -{ - debugOutput(DEBUG_LEVEL_NORMAL, "(%p) PosixSharedMemory %s\n", this, m_name.c_str()); -} - -} // namespace Util Index: /anches/libffado-2.0/src/libutil/cycles.h =================================================================== --- /branches/libffado-2.0/src/libutil/cycles.h (revision 864) +++ (revision ) @@ -1,119 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* cycles.h - * Based upon cycles.h from the jackdmp package. - * Original Copyright: - * - * Copyright (C) 2001 Paul Davis - * Code derived from various headers from the Linux kernel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef __FFADO_CYCLES_H__ -#define __FFADO_CYCLES_H__ - -/* - * Standard way to access the cycle timer on i586+ CPUs. - * Currently only used on SMP. - * - * If you really have a SMP machine with i486 chips or older, - * compile for that, and this will just always return zero. - * That's ok, it just means that the nicer scheduling heuristics - * won't work for you. - * - * We only use the low 32 bits, and we'd simply better make sure - * that we reschedule before that wraps. Scheduling at least every - * four billion cycles just basically sounds like a good idea, - * regardless of how fast the machine is. - */ - -#ifdef __linux__ - -#ifdef __PPC__ - -/* PowerPC */ - -#define CPU_FTR_601 0x00000100 - -typedef unsigned long cycles_t; - -/* For the "cycle" counter we use the timebase lower half. */ - -extern cycles_t cacheflush_time; - -static inline cycles_t get_cycles(void) -{ - cycles_t ret = 0; - - __asm__ __volatile__( - "98: mftb %0\n" - "99:\n" - ".section __ftr_fixup,\"a\"\n" - " .long %1\n" - " .long 0\n" - " .long 98b\n" - " .long 99b\n" - ".previous" - : "=r" (ret) : "i" (CPU_FTR_601)); - return ret; -} - -#endif - -#ifdef __i386__ - -typedef unsigned long long cycles_t; - -extern cycles_t cacheflush_time; - -#define rdtscll(val) \ - __asm__ __volatile__("rdtsc" : "=A" (val)) - -static inline cycles_t get_cycles (void) -{ - unsigned long long ret; - - rdtscll(ret); - return ret; -} - -#endif - -#endif - -#endif // __FFADO_CYCLES_H__ Index: /anches/libffado-2.0/src/libutil/IpcRingBuffer.h =================================================================== --- /branches/libffado-2.0/src/libutil/IpcRingBuffer.h (revision 1172) +++ (revision ) @@ -1,211 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __UTIL_IPC_RINGBUFFER__ -#define __UTIL_IPC_RINGBUFFER__ - -#include "debugmodule/debugmodule.h" -#include - -#include "config.h" - -#define FFADO_IPC_RINGBUFFER_MAGIC 0x57439812 -#define FFADO_IPC_RINGBUFFER_VERSION 0 - -#define FFADO_IPC_MAX_MESSAGE_SIZE 16 - -#include "PosixMessageQueue.h" - -#include - -namespace Util { - -/** - * @brief A Ringbuffer for IPC use. - */ - -class PosixMessageQueue; -class PosixSharedMemory; -class Mutex; -class Functor; - -class IpcRingBuffer -{ -// the message types -protected: - enum eMessagePriorities { - eMP_Realtime = 10, - }; - - // these are the views on the message contents - struct DataWrittenMessage { - unsigned int idx; - unsigned int id; - }; - - class IpcMessage : public PosixMessageQueue::Message - { - public: - enum eMessageType { - eMT_Unknown = 0, - eMT_DataWritten = 1, - eMT_DataAck = 2, - }; - - IpcMessage() - : Message() - , m_priority( 0 ) - , m_data_len( 0 ) - { - m_header.magic = FFADO_IPC_RINGBUFFER_MAGIC; - m_header.version = FFADO_IPC_RINGBUFFER_VERSION; - m_header.type = eMT_Unknown; - }; - - IpcMessage(enum eMessageType t) - : Message() - , m_priority( 0 ) - , m_data_len( 0 ) - { - m_header.magic = FFADO_IPC_RINGBUFFER_MAGIC; - m_header.version = FFADO_IPC_RINGBUFFER_VERSION; - m_header.type = t; - }; - - virtual ~IpcMessage() {}; - - virtual unsigned getPriority() - {return m_priority;}; - virtual unsigned int getLength() - {return sizeof(m_header) - + sizeof(m_data);}; - - virtual bool serialize(char *buff); - virtual bool deserialize(const char *buff, unsigned int length, unsigned prio); - - void setType(enum eMessageType t) {m_header.type=t;}; - enum eMessageType getType() {return m_header.type;}; - char *getDataPtr() {return m_data;}; - void setDataSize(unsigned int i) - { assert(i( configRom ) ) { - -#ifdef ENABLE_BOUNCE - if ( Bounce::BounceSlaveDevice::probe( *configRom.get() ) ) { - return Bounce::BounceSlaveDevice::createDevice( configRom ); - } -#endif - return 0; } @@ -983,12 +923,4 @@ } return device->getStreamProcessorByIndex(0); -/* - #warning TEST CODE FOR BOUNCE DEVICE !! - // this makes the bounce slave use the xmit SP as sync source - if (slaveMode) { - return device->getStreamProcessorByIndex(1); - } else { - return device->getStreamProcessorByIndex(0); - }*/ } Index: /branches/libffado-2.0/README =================================================================== --- /branches/libffado-2.0/README (revision 1055) +++ /branches/libffado-2.0/README (revision 1190) @@ -1,3 +1,3 @@ -FFADO v2.x +FFADO v2.0 ========== @@ -40,4 +40,5 @@ * Terratec Producer Phase 88 * Focusrite Saffire (original/white) +* Focusrite Saffire LE (black) * Focusrite Saffire PRO10 * Focusrite Saffire PRO26 @@ -48,5 +49,5 @@ The 'officially supported' label is only given to devices that fullfil the following: -* at least one of the developers has the device +* at least one of the developers has the device, or a closely related one * the vendor provides development support (access to information) * the device works @@ -71,9 +72,10 @@ * Presonus FireBox * Presonus FirePod / FP10 -* Focusrite Saffire LE * ECHO AudioFire8 * ECHO AudioFire12 - -Usupported devices: +* Terratec Producer Phase 24 +* Terratec Producer Phase X24 + +Unsupported devices (non-functional): * Presonus FireStation * Presonus FireStudio (all variants) @@ -82,6 +84,10 @@ * Metric Halo devices * RME Firewire devices - -We constantly try to persuade vendors to help us extend our device support. +* M-Audio FireWire 410 +* M-Audio FireWire 1814 +* M-Audio ProFire 2626 + +We constantly try to persuade vendors to help us extend our device support. Don't +hesitate to let a vendor know that you would like to have their device(s) supported. Dependencies Index: /branches/libffado-2.0/tests/SConscript =================================================================== --- /branches/libffado-2.0/tests/SConscript (revision 1185) +++ /branches/libffado-2.0/tests/SConscript (revision 1190) @@ -45,27 +45,5 @@ apps = { "test-ffado" : "test-ffado.cpp", - "test-fw410" : "test-fw410.cpp", - "test-avccmd" : "test-avccmd.cpp", - #"test-extplugcmd" : "test-extplugcmd.cpp", - #"test-volume" : "test-volume.cpp", - #"test-mixer" : "test-mixer.cpp", - "test-enhanced-mixer" : "test-enhanced-mixer.cpp", - "test-timestampedbuffer" : "test-timestampedbuffer.cpp", - "test-ieee1394service" : "test-ieee1394service.cpp", - "test-streamdump" : "test-streamdump.cpp", - "test-bufferops" : "test-bufferops.cpp", - "test-watchdog" : "test-watchdog.cpp", - "test-messagequeue" : "test-messagequeue.cpp", - "test-shm" : "test-shm.cpp", - "test-ipcringbuffer" : "test-ipcringbuffer.cpp", - "test-devicestringparser" : "test-devicestringparser.cpp", - "dumpiso_mod" : "dumpiso_mod.cpp", - "scan-devreg" : "scan-devreg.cpp" } - -if env['ENABLE_BEBOB']: - apps.update( { "test-focusrite" : "test-focusrite.cpp" } ) -if env['ENABLE_FIREWORKS']: - apps.update( { "test-echomixer" : "test-echomixer.cpp" } ) for app in apps.keys(): Index: /branches/libffado-2.0/tests/systemtests/SConscript =================================================================== --- /branches/libffado-2.0/tests/systemtests/SConscript (revision 1154) +++ /branches/libffado-2.0/tests/systemtests/SConscript (revision 1190) @@ -42,7 +42,4 @@ "test-isorecv-1" : ["test-isorecv-1.cpp", "realtimetools.cpp"], "test-isoxmit-1" : ["test-isoxmit-1.cpp", "realtimetools.cpp"], - "test-sysload" : ["test-sysload.cpp", "realtimetools.cpp"], - "gen-loadpulses" : ["gen-loadpulses.cpp", "realtimetools.cpp"], - "test-clock_nanosleep" : ["test-clock_nanosleep.cpp", "realtimetools.cpp"], } Index: /anches/libffado-2.0/tests/systemtests/gen-loadpulses.cpp =================================================================== --- /branches/libffado-2.0/tests/systemtests/gen-loadpulses.cpp (revision 1148) +++ (revision ) @@ -1,203 +1,0 @@ -/* - * Parts Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* - * based on howdyget.c (unknown source, maybe Maas Digital LLC) - */ - -#include -#include -#include -#include - -#include - -#include - -#include "debugmodule/debugmodule.h" -#include "realtimetools.h" - -uint32_t count = 0; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_EXTRA_ARGS 2 -// Program documentation. -// Program documentation. -static char doc[] = "FFADO -- System Load pulse generator\n\n"; - -// A description of the arguments we accept. -static char args_doc[] = ""; - -struct arguments -{ - long int verbose; - long int rtprio; - long int period; - long int duration; - long int countdown; - char* args[MAX_EXTRA_ARGS]; -}; - -// The options we understand. -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Verbose level" }, - {"rtprio", 'P', "prio", 0, "real time priority of the iterator process/thread (0 = no RT)" }, - {"period", 'p', "usecs", 0, "period (in usecs)" }, - {"duration", 'd', "usecs", 0, "pulse duration (in usecs)" }, - {"countdown", 'u', "count", 0, "number of pulses to run" }, - { 0 } -}; - -// Parse a single option. -#define PARSE_ARG_LONG(XXletterXX, XXvarXX, XXdescXX) \ - case XXletterXX: \ - if (arg) { \ - XXvarXX = strtol( arg, &tail, 0 ); \ - if ( errno ) { \ - fprintf( stderr, "Could not parse '%s' argument\n", XXdescXX ); \ - return ARGP_ERR_UNKNOWN; \ - } \ - } \ - break; - -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - char* tail; - - errno = 0; - switch (key) { - PARSE_ARG_LONG('v', arguments->verbose, "verbose"); - PARSE_ARG_LONG('P', arguments->rtprio, "rtprio"); - PARSE_ARG_LONG('p', arguments->period, "period"); - PARSE_ARG_LONG('d', arguments->duration, "duration"); - PARSE_ARG_LONG('u', arguments->countdown, "countdown"); - - case ARGP_KEY_ARG: - break; - case ARGP_KEY_END: - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -// Our argp parser. -static struct argp argp = { options, parse_opt, args_doc, doc }; - -// the global arguments struct -struct arguments arguments; - -// signal handler -int run; -static void sighandler (int sig) -{ - run = 0; -} - -// the load function -float global; -void load_function() { - int cnt = 10; - while(cnt--) { - int global_int = (int)global; - global = global / 7.0; - global_int++; - global += (float)global_int; - } -} - -int main(int argc, char **argv) -{ - // register signal handler - run = 1; - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - // Default values. - arguments.verbose = DEBUG_LEVEL_VERBOSE; - arguments.rtprio = 0; - arguments.countdown = 1000; - arguments.period = 1000; - arguments.duration = 100; - - // Parse our arguments; every option seen by `parse_opt' will - // be reflected in `arguments'. - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - debugError("Could not parse command line\n" ); - return -1; - } - - debugOutput(DEBUG_LEVEL_INFO, "System Load pulse generator\n"); - debugOutput(DEBUG_LEVEL_INFO, " Arguments:\n"); - debugOutput(DEBUG_LEVEL_INFO, " RT priority : %d\n", arguments.rtprio); - debugOutput(DEBUG_LEVEL_INFO, " Countdown : %d\n", arguments.countdown); - debugOutput(DEBUG_LEVEL_INFO, " Period : %d usec\n", arguments.period); - debugOutput(DEBUG_LEVEL_INFO, " Pulse duration : %d usec\n", arguments.duration); - - debugOutput(DEBUG_LEVEL_INFO, "Setting RT priority (%d)...\n", arguments.rtprio); - set_realtime_priority(arguments.rtprio); - - debugOutput(DEBUG_LEVEL_INFO, "Starting iterate loop...\n"); - flushDebugOutput(); - - int countdown = arguments.countdown; - uint64_t sleep_time = rt_gettime_usecs(); - while(countdown-- && run) - { - // figure out when to stop calling the load function - uint64_t run_until = sleep_time + arguments.duration; - - while(rt_gettime_usecs() < run_until) load_function(); - - // now wait for the period to end - sleep_time += arguments.period; - rt_sleep_absolute_usecs(sleep_time); - - // check if we are late - uint64_t toc = rt_gettime_usecs(); - int64_t usecs_late = toc - sleep_time; - if(usecs_late > 1000) { - debugWarning("late wakeup: %lld usecs\n", usecs_late); - } - - // try and detect lockup () - if(usecs_late > 100000) { - debugWarning("very late wakeup: %lld usecs\n", usecs_late); - // force exit, since this is a loop out of control - run=0; - } - } - - if(run) { - debugOutput(DEBUG_LEVEL_INFO, "Clean exit...\n"); - } else { - debugOutput(DEBUG_LEVEL_INFO, "Forced exit...\n"); - } - return 0; -} Index: /branches/libffado-2.0/tests/streaming/SConscript =================================================================== --- /branches/libffado-2.0/tests/streaming/SConscript (revision 1172) +++ /branches/libffado-2.0/tests/streaming/SConscript (revision 1190) @@ -30,5 +30,5 @@ env.PrependUnique( LIBS=["ffado"] ) -cppapps = "teststreaming3 teststreaming-ipc test-ipcclient" +cppapps = "teststreaming3" for app in env.Split( cppapps ): Index: /anches/libffado-2.0/tests/streaming/teststreaming-ipc.cpp =================================================================== --- /branches/libffado-2.0/tests/streaming/teststreaming-ipc.cpp (revision 1172) +++ (revision ) @@ -1,616 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - - -/** - * Test application for the IPC audio server - */ - -#include "config.h" - -#include -#include -#include - -#include -#include - -#include "libffado/ffado.h" - -#include "debugmodule/debugmodule.h" - -#include "libutil/IpcRingBuffer.h" -#include "libutil/SystemTimeSource.h" - -#include -#include - -int run; - -DECLARE_GLOBAL_DEBUG_MODULE; - -using namespace Util; - -// Program documentation. -// Program documentation. -static char doc[] = "FFADO -- a driver for Firewire Audio devices (IPC streaming test application)\n\n" - ; - -// A description of the arguments we accept. -static char args_doc[] = ""; - -struct arguments -{ - long int verbose; - long int test_tone; - long int test_tone_freq; - long int period; - long int slave_mode; - long int snoop_mode; - long int nb_buffers; - long int sample_rate; - long int rtprio; - long int audio_buffer_type; - long int playback; - long int capture; - char* args[2]; - -}; - -// The options we understand. -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Verbose level" }, - {"rtprio", 'P', "prio", 0, "Realtime priority (0 = no RT scheduling)" }, - {"test-tone", 't', "bool", 0, "Output test sine" }, - {"test-tone-freq", 'f', "hz", 0, "Test sine frequency" }, - {"samplerate", 'r', "hz", 0, "Sample rate" }, - {"period", 'p', "frames", 0, "Period (buffer) size" }, - {"nb_buffers", 'n', "nb", 0, "Nb buffers (periods)" }, - {"slave_mode", 's', "bool", 0, "Run in slave mode" }, - {"snoop_mode", 'S', "bool", 0, "Run in snoop mode" }, - {"audio_buffer_type", 'b', "", 0, "Datatype of audio buffers (0=float, 1=int24)" }, - {"playback", 'o', "", 0, "Number of playback channels" }, - {"capture", 'i', "", 0, "Number of capture channels" }, - { 0 } -}; - -//------------------------------------------------------------- - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - char* tail; - - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'P': - if (arg) { - arguments->rtprio = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'rtprio' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'p': - if (arg) { - arguments->period = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'period' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'n': - if (arg) { - arguments->nb_buffers = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'nb_buffers' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'r': - if (arg) { - arguments->sample_rate = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'samplerate' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 't': - if (arg) { - arguments->test_tone = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'test-tone' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'f': - if (arg) { - arguments->test_tone_freq = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'test-tone-freq' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'b': - if (arg) { - arguments->audio_buffer_type = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'audio-buffer-type' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'i': - if (arg) { - arguments->capture = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'capture' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'o': - if (arg) { - arguments->playback = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'playback' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 's': - if (arg) { - arguments->slave_mode = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'slave_mode' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'S': - if (arg) { - arguments->snoop_mode = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'snoop_mode' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case ARGP_KEY_ARG: - break; - case ARGP_KEY_END: - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -// Our argp parser. -static struct argp argp = { options, parse_opt, args_doc, doc }; - -int set_realtime_priority(unsigned int prio) -{ - debugOutput(DEBUG_LEVEL_NORMAL, "Setting thread prio to %u\n", prio); - if (prio > 0) { - struct sched_param schp; - /* - * set the process to realtime privs - */ - memset(&schp, 0, sizeof(schp)); - schp.sched_priority = prio; - - if (sched_setscheduler(0, SCHED_FIFO, &schp) != 0) { - perror("sched_setscheduler"); - return -1; - } - } else { - struct sched_param schp; - /* - * set the process to realtime privs - */ - memset(&schp, 0, sizeof(schp)); - schp.sched_priority = 0; - - if (sched_setscheduler(0, SCHED_OTHER, &schp) != 0) { - perror("sched_setscheduler"); - return -1; - } - } - return 0; -} - -static void sighandler (int sig) -{ - run = 0; -} - -int main(int argc, char *argv[]) -{ - - struct arguments arguments; - - // Default values. - arguments.verbose = 6; - arguments.period = 1024; - arguments.slave_mode = 0; - arguments.snoop_mode = 0; - arguments.nb_buffers = 3; - arguments.sample_rate = 44100; - arguments.rtprio = 0; - arguments.audio_buffer_type = 1; - arguments.playback = 0; - arguments.capture = 0; - - // Parse our arguments; every option seen by `parse_opt' will - // be reflected in `arguments'. - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - debugError("Could not parse command line\n" ); - return -1; - } - - debugOutput(DEBUG_LEVEL_NORMAL, "verbose level = %d\n", arguments.verbose); - setDebugLevel(arguments.verbose); - - if(arguments.playback == 0 && arguments.capture == 0) { - debugError("No playback nor capture channels requested\n"); - return -1; - } - - int nb_in_channels=0, nb_out_channels=0; - int i=0; - int start_flag = 0; - - int nb_periods=0; - - uint32_t **audiobuffers_in = NULL; - uint32_t **audiobuffers_out = NULL; - float *nullbuffer = NULL; - - run=1; - - debugOutput(DEBUG_LEVEL_NORMAL, "FFADO streaming test application (3)\n"); - - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - ffado_device_info_t device_info; - memset(&device_info,0,sizeof(ffado_device_info_t)); - - ffado_options_t dev_options; - memset(&dev_options,0,sizeof(ffado_options_t)); - - dev_options.sample_rate = arguments.sample_rate; - dev_options.period_size = arguments.period; - - dev_options.nb_buffers = arguments.nb_buffers; - - dev_options.realtime = (arguments.rtprio != 0); - dev_options.packetizer_priority = arguments.rtprio; - - dev_options.verbose = arguments.verbose; - - dev_options.slave_mode = arguments.slave_mode; - dev_options.snoop_mode = arguments.snoop_mode; - - ffado_device_t *dev=ffado_streaming_init(device_info, dev_options); - - if (!dev) { - debugError("Could not init Ffado Streaming layer\n"); - exit(-1); - } - if (arguments.audio_buffer_type == 0) { - ffado_streaming_set_audio_datatype(dev, ffado_audio_datatype_float); - } else { - ffado_streaming_set_audio_datatype(dev, ffado_audio_datatype_int24); - } - - int nb_in_channels_all = ffado_streaming_get_nb_capture_streams(dev); - int nb_out_channels_all = ffado_streaming_get_nb_playback_streams(dev); - - // only do audio for now - for (i=0; i < nb_in_channels_all; i++) { - switch (ffado_streaming_get_capture_stream_type(dev,i)) { - case ffado_stream_type_audio: - nb_in_channels++; - break; - case ffado_stream_type_midi: - default: - break; - } - } - for (i=0; i < nb_out_channels_all; i++) { - switch (ffado_streaming_get_playback_stream_type(dev,i)) { - case ffado_stream_type_audio: - nb_out_channels++; - break; - case ffado_stream_type_midi: - default: - break; - } - } - - printMessage("Channel count: %d capture, %d playback\n", - nb_in_channels, nb_out_channels); - - if(arguments.playback > nb_out_channels) { - debugError("Too many playback channels requested (want: %d, have:%d)\n", - arguments.playback, nb_out_channels); - return -1; - } - if(arguments.capture > nb_in_channels) { - debugError("Too many capture channels requested (want: %d, have:%d)\n", - arguments.capture, nb_in_channels); - return -1; - } - - printMessage("Buffer size: %d capture, %d playback\n", - nb_in_channels*dev_options.period_size * 4, - nb_out_channels*dev_options.period_size * 4); - - // allocate the IPC structures - #define NB_BUFFERS 4 - IpcRingBuffer* capturebuffer = NULL; - IpcRingBuffer* playbackbuffer = NULL; - if(arguments.capture) { - // 4 bytes per channel per sample - capturebuffer = new IpcRingBuffer("capturebuffer", - IpcRingBuffer::eBT_Master, - IpcRingBuffer::eD_Outward, - IpcRingBuffer::eB_NonBlocking, - NB_BUFFERS, dev_options.period_size * arguments.capture * 4); - if(capturebuffer == NULL) { - debugError("Could not create capture IPC buffer\n"); - exit(-1); - } - - capturebuffer->setVerboseLevel(arguments.verbose); - - if(!capturebuffer->init()) { - debugError("Could not init capture buffer\n"); - delete capturebuffer; - exit(-1); - } - // indexes to the memory locations where the frames should be put - audiobuffers_in = (uint32_t **)calloc(arguments.capture, sizeof(uint32_t *)); - } - - if(arguments.playback) { - // 4 bytes per channel per sample - playbackbuffer = new IpcRingBuffer("playbackbuffer", - IpcRingBuffer::eBT_Master, - IpcRingBuffer::eD_Inward, - IpcRingBuffer::eB_NonBlocking, - NB_BUFFERS, dev_options.period_size * arguments.playback * 4); - if(playbackbuffer == NULL) { - debugError("Could not create playback IPC buffer\n"); - exit(-1); - } - - playbackbuffer->setVerboseLevel(arguments.verbose); - - if(!playbackbuffer->init()) { - debugError("Could not init playback buffer\n"); - delete capturebuffer; - delete playbackbuffer; - exit(-1); - } - // indexes to the memory locations where the frames should be get - audiobuffers_out = (uint32_t **)calloc(arguments.playback, sizeof(uint32_t *)); - } - - // this serves in case we miss a cycle, or a channel is disabled - nullbuffer = (float *)calloc(arguments.period, sizeof(float)); - - // give us RT prio - set_realtime_priority(arguments.rtprio); - - // start the streaming layer - if (ffado_streaming_prepare(dev)) { - debugFatal("Could not prepare streaming system\n"); - ffado_streaming_finish(dev); - return -1; - } - start_flag = ffado_streaming_start(dev); - - // enter the loop - debugOutput(DEBUG_LEVEL_NORMAL, - "Entering receive loop (IN: %d, OUT: %d)\n", - arguments.capture, arguments.playback); - - while(run && start_flag==0) { - bool need_silent; - enum IpcRingBuffer::eResult msg_res; - - ffado_wait_response response; - response = ffado_streaming_wait(dev); - if (response == ffado_wait_xrun) { - debugOutput(DEBUG_LEVEL_NORMAL, "Xrun\n"); - ffado_streaming_reset(dev); - continue; - } else if (response == ffado_wait_error) { - debugError("fatal xrun\n"); - break; - } - - // get a block pointer from the IPC buffer to write - if(arguments.capture) { - uint32_t *audiobuffers_raw; - msg_res = capturebuffer->requestBlockForWrite((void**) &audiobuffers_raw); // pointer voodoo - if(msg_res == IpcRingBuffer::eR_OK) { - // if we got a valid pointer, setup the stream pointers - for (i=0; i < nb_in_channels; i++) { - if(i < arguments.capture) { - audiobuffers_in[i] = audiobuffers_raw + i*dev_options.period_size; - switch (ffado_streaming_get_capture_stream_type(dev,i)) { - case ffado_stream_type_audio: - /* assign the audiobuffer to the stream */ - ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); - ffado_streaming_capture_stream_onoff(dev, i, 1); - break; - // this is done with read/write routines because the nb of bytes can differ. - case ffado_stream_type_midi: - ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(audiobuffers_in[i])); - ffado_streaming_capture_stream_onoff(dev, i, 1); - default: - break; - } - } else { - ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_capture_stream_onoff(dev, i, 0); - } - } - need_silent = false; - } else { - need_silent = true; - debugOutput(DEBUG_LEVEL_NORMAL, "CAP: missed period %d\n", nb_periods); - } - } - if(need_silent) { - // if not, use the null buffer - for (i=0; i < nb_in_channels; i++) { - switch (ffado_streaming_get_capture_stream_type(dev,i)) { - case ffado_stream_type_audio: - /* assign the audiobuffer to the stream */ - ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_capture_stream_onoff(dev, i, 0); - break; - // this is done with read/write routines because the nb of bytes can differ. - case ffado_stream_type_midi: - ffado_streaming_set_capture_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_capture_stream_onoff(dev, i, 0); - default: - break; - } - } - } - - // transfer - ffado_streaming_transfer_capture_buffers(dev); - - if(!need_silent && msg_res == IpcRingBuffer::eR_OK) { - // if we had a good block, release it - // FIXME: we should check for errors here - capturebuffer->releaseBlockForWrite(); - } - - if(arguments.playback) { - uint32_t *audiobuffers_raw; - // get a block pointer from the IPC buffer to read - msg_res = playbackbuffer->requestBlockForRead((void**) &audiobuffers_raw); // pointer voodoo - if(msg_res == IpcRingBuffer::eR_OK) { - // if we got a valid pointer, setup the stream pointers - for (i=0; i < nb_out_channels; i++) { - if(i < arguments.playback) { - audiobuffers_out[i] = audiobuffers_raw + i*dev_options.period_size; - switch (ffado_streaming_get_playback_stream_type(dev,i)) { - case ffado_stream_type_audio: - /* assign the audiobuffer to the stream */ - ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_out[i])); - ffado_streaming_playback_stream_onoff(dev, i, 1); - break; - // this is done with read/write routines because the nb of bytes can differ. - case ffado_stream_type_midi: - ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(audiobuffers_out[i])); - ffado_streaming_playback_stream_onoff(dev, i, 1); - default: - break; - } - } else { - ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_playback_stream_onoff(dev, i, 0); - } - } - need_silent=false; - } else { - debugOutput(DEBUG_LEVEL_NORMAL, "PBK: missed period %d\n", nb_periods); - need_silent=true; - } - } else { - need_silent=true; - } - if(need_silent) { - // if not, use the null buffer - memset(nullbuffer, 0, arguments.period * sizeof(float)); // clean it first - for (i=0; i < nb_out_channels; i++) { - switch (ffado_streaming_get_playback_stream_type(dev,i)) { - case ffado_stream_type_audio: - /* assign the audiobuffer to the stream */ - ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_playback_stream_onoff(dev, i, 0); - break; - // this is done with read/write routines because the nb of bytes can differ. - case ffado_stream_type_midi: - ffado_streaming_set_playback_stream_buffer(dev, i, (char *)(nullbuffer)); - ffado_streaming_playback_stream_onoff(dev, i, 0); - default: - break; - } - } - } - - // transfer playback buffers - ffado_streaming_transfer_playback_buffers(dev); - - if(!need_silent && msg_res == IpcRingBuffer::eR_OK) { - // if we had a good block, release it - // FIXME: we should check for errors here - capturebuffer->releaseBlockForRead(); - } - - nb_periods++; - } - - debugOutput(DEBUG_LEVEL_NORMAL, "Exiting receive loop\n"); - - ffado_streaming_stop(dev); - ffado_streaming_finish(dev); - - delete capturebuffer; - delete playbackbuffer; - - free(nullbuffer); - free(audiobuffers_in); - free(audiobuffers_out); - - return EXIT_SUCCESS; -} Index: /anches/libffado-2.0/tests/streaming/test-ipcclient.cpp =================================================================== --- /branches/libffado-2.0/tests/streaming/test-ipcclient.cpp (revision 1172) +++ (revision ) @@ -1,282 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "debugmodule/debugmodule.h" - -#include "libutil/IpcRingBuffer.h" -#include "libutil/SystemTimeSource.h" - -#include -#include -#include -#include - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 2 - -int run=1; -int lastsig=-1; -static void sighandler (int sig) -{ - run = 0; -} - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-ipcringbuffer 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to test the ipc ringbuffer class."; -static char args_doc[] = "DIRECTION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - {"playback", 'o', "count", 0, "Number of playback channels" }, - {"capture", 'i', "count", 0, "Number of capture channels" }, - {"period", 'p', "frames", 0, "Period size in frames" }, - {"nb_buffers", 'n', "count", 0, "Number of IPC buffers" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - , playback( 0 ) - , capture( 0 ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - long int verbose; - long int playback; - long int capture; - long int period; - long int nb_buffers; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'o': - if (arg) { - arguments->playback = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'playback' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'i': - if (arg) { - arguments->capture = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'capture' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'p': - if (arg) { - arguments->period = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'periods' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'n': - if (arg) { - arguments->nb_buffers = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'nb_buffers' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs <= 0) { - printMessage("not enough arguments\n"); - return -1; - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - - setDebugLevel(arguments.verbose); - - if(arguments.playback == 0 && arguments.capture == 0) { - debugError("No playback nor capture channels requested\n"); - return -1; - } - - printMessage("Testing shared memory streaming IPC\n"); - - // prepare the IPC buffers - unsigned int capture_buffsize = arguments.capture * arguments.period * 4; - unsigned int playback_buffsize = arguments.playback * arguments.period * 4; - IpcRingBuffer* capturebuffer = NULL; - IpcRingBuffer* playbackbuffer = NULL; - if(arguments.playback == 0) { - playbackbuffer = new IpcRingBuffer("playbackbuffer", - IpcRingBuffer::eBT_Slave, - IpcRingBuffer::eD_Outward, - IpcRingBuffer::eB_Blocking, - arguments.nb_buffers, playback_buffsize); - if(playbackbuffer == NULL) { - debugError("Could not create playbackbuffer\n"); - exit(-1); - } - if(!playbackbuffer->init()) { - debugError("Could not init playbackbuffer\n"); - delete playbackbuffer; - exit(-1); - } - playbackbuffer->setVerboseLevel(arguments.verbose); - } - if(arguments.capture) { - capturebuffer = new IpcRingBuffer("capturebuffer", - IpcRingBuffer::eBT_Slave, - IpcRingBuffer::eD_Inward, - IpcRingBuffer::eB_Blocking, - arguments.nb_buffers, capture_buffsize); - if(capturebuffer == NULL) { - debugError("Could not create capturebuffer\n"); - delete playbackbuffer; - exit(-1); - } - if(!capturebuffer->init()) { - debugError("Could not init capturebuffer\n"); - delete playbackbuffer; - delete capturebuffer; - exit(-1); - } - capturebuffer->setVerboseLevel(arguments.verbose); - } - - - // dummy buffers - char capture_buff[capture_buffsize]; - char playback_buff[playback_buffsize]; - - int cnt = 0; - - - run=1; - while(run) { - // write the data - IpcRingBuffer::eResult res; - res = playbackbuffer->Write(playback_buff); - if(res != IpcRingBuffer::eR_OK && res != IpcRingBuffer::eR_Again) { - debugError("Could not write to segment\n"); - goto out_err; - } - if(res == IpcRingBuffer::eR_Again) { - printMessage(" Try playback again on %d...\n", cnt); - } - - res = capturebuffer->Read(capture_buff); - if(res != IpcRingBuffer::eR_OK && res != IpcRingBuffer::eR_Again) { - debugError("Could not receive from queue\n"); - goto out_err; - } - if(res == IpcRingBuffer::eR_Again) { - printMessage(" Try again on %d...\n", cnt); - } else { - if(cnt%10==0) { - uint32_t *tmp = (uint32_t *)capture_buff; - for(int i=0;i. - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include -#include "src/debugmodule/debugmodule.h" - -#include "libutil/ByteSwap.h" - -#include "src/libutil/PosixThread.h" - -#include "src/libstreaming/util/IsoHandler.h" -#include "src/libstreaming/util/StreamProcessorManager.h" -#include "src/libstreaming/util/IsoHandlerManager.h" -#include "src/libstreaming/amdtp/AmdtpStreamProcessor.h" -#include "src/libstreaming/amdtp/AmdtpPort.h" - -using namespace Streaming; - -int run; - -static void sighandler (int sig) -{ - run = 0; -} - -int main(int argc, char *argv[]) -{ - - int retval=0; - int i=0; - run=1; - - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - printf("FFADO streaming test application\n"); - printf(" ISO handler tests\n"); - - // also create a processor manager to manage the actual stream - // processors - StreamProcessorManager *procMan = new StreamProcessorManager(512,3); - if(!procMan) { - printf("Could not create StreamProcessorManager\n"); - return -1; - } - procMan->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - - // now we can allocate the stream processors themselves - -// StreamProcessor *spt = new AmdtpTransmitStreamProcessor(3,2,44100,10); -// if(!spt) { -// printf("Could not create transmit AmdtpTransmitStreamProcessor\n"); -// return -1; -// } -// spt->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - - AmdtpReceiveStreamProcessor *spr = new AmdtpReceiveStreamProcessor(2,44100,7); -// ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100); - if(!spr) { - printf("Could not create receive AmdtpStreamProcessor\n"); - return -1; - } - spr->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - spr->setChannel(0); - - AmdtpReceiveStreamProcessor *spr2 = new AmdtpReceiveStreamProcessor(2,44100,11); -// ReceiveStreamProcessor *spr = new ReceiveStreamProcessor(0,2,44100); - if(!spr2) { - printf("Could not create receive AmdtpStreamProcessor\n"); - return -1; - } - spr2->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - spr2->setChannel(1); - -// printf("----------------------\n"); -// if (procMan->registerProcessor(spt)) { -// printf("Could not register transmit stream processor with the Processor manager\n"); -// return -1; -// } -// printf("----------------------\n"); - - // also register it with the processor manager, so that it is aware of - // buffer sizes etc... - if (procMan->registerProcessor(spr)) { - printf("Could not register receive stream processor with the Processor manager\n"); - return -1; - } - printf("----------------------\n"); - - if (procMan->registerProcessor(spr2)) { - printf("Could not register receive stream processor with the Processor manager\n"); - return -1; - } - printf("----------------------\n"); - - AmdtpAudioPort *p1=new AmdtpAudioPort( - std::string("Test port 1"), - AmdtpAudioPort::E_Capture, - 1, - 0, - AmdtpPortInfo::E_MBLA, - 0 - ); - if (!p1) { - printf("Could not create port 1\n"); - return -1; - } - - p1->setBufferSize(512); - - printf("----------------------\n"); - - if (spr2->addPort(p1)) { - printf("Could not register port with receive stream processor\n"); - return -1; - } - - Util::PosixThread *thread=new Util::PosixThread(procMan); - - - procMan->prepare(); - - // start the runner - thread->Start(); - printf("----------------------\n"); - - if(procMan->start()) { - printf("Could not start handlers\n"); - return -1; - } - printf("----------------------\n"); - - int periods=0; - int periods_print=0; - while(run) { - periods++; - if(periods>periods_print) { - printf("\n"); - printf("============================================\n"); - procMan->dumpInfo(); - printf("--------------------------------------------\n"); -/* hexDumpQuadlets((quadlet_t*)(p1->getBufferAddress()),10); - printf("--------------------------------------------\n");*/ - hexDumpQuadlets((quadlet_t*)(p1->getBufferAddress()),10); - printf("============================================\n"); - printf("\n"); - periods_print+=100; - } - procMan->waitForPeriod(); - procMan->transfer(); - - } - - thread->Stop(); - - procMan->stop(); - -// procMan->unregisterProcessor(spt); - procMan->unregisterProcessor(spr); - procMan->unregisterProcessor(spr2); - - delete thread; - - delete procMan; - -// delete spt; - delete spr; - delete spr2; - - printf("Bye...\n"); - - - return EXIT_SUCCESS; -} Index: /anches/libffado-2.0/tests/scan-devreg.cpp =================================================================== --- /branches/libffado-2.0/tests/scan-devreg.cpp (revision 1136) +++ (revision ) @@ -1,305 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * Copyright (C) 2005-2008 by Daniel Wagner - * Copyright (C) 2008 by Jonathan Woithe - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include "libutil/ByteSwap.h" - -#include "debugmodule/debugmodule.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" -#include "libutil/Time.h" - -#include -#include -#include - -using namespace std; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 1000 - -#define MOTU_BASE_ADDR 0xfffff0000000ULL - -// If changing these be sure to update the option help text -#define DEFAULT_SCAN_START_REG 0x0b00 -#define DEFAULT_SCAN_LENGTH 0x0200 - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "scan-devreg 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "scan-devreg -- scan device registers for changes."; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', "LEVEL", 0, "Set verbose level" }, - {"port", 'p', "PORT", 0, "Set port" }, - {"node", 'n', "NODE", 0, "Set node" }, - {"start", 's', "REG", 0, "Register to start scan at (default: 0x0b00)" }, - {"length", 'l', "LENGTH", 0, "Number of bytes of register space to scan (default: 0x0200)" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( 0 ) - , test( false ) - , port( -1 ) - , node ( -1 ) - , scan_start ( DEFAULT_SCAN_START_REG ) - , scan_length ( DEFAULT_SCAN_LENGTH ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - signed int verbose; - bool test; - signed int port; - signed int node; - signed int scan_start; - signed int scan_length; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - switch (key) { - case 'v': - errno = 0; - arguments->verbose = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 't': - arguments->test = true; - break; - case 's': - errno = 0; - arguments->scan_start = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - if (arguments->scan_start < 0) { - fprintf(stderr, "Start of scan must be >= 0\n"); - return -1; - } - break; - case 'l': - errno = 0; - arguments->scan_length = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - if (arguments->scan_length < 0) { - fprintf(stderr, "Scan length must be >= 0\n"); - return -1; - } - break; - case 'p': - errno = 0; - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 'n': - errno = 0; - arguments->node = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - signed int loop = 0; - char chr[100]; - signed int node_id = -1; - signed int port = -1; - signed int n_ports = -1; - signed int p1, p2, n1, n2; - - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - errno = 0; - - setDebugLevel(arguments.verbose); - - // Do a really basic scan to find an audio device on the bus - n_ports = Ieee1394Service::detectNbPorts(); - if (arguments.port < 0) { - p1 = 0; - p2 = n_ports; - } else { - // Scan a specific port if given on the command line - p1 = p2 = arguments.port; - p2++; - } - printf("Scanning %d firewire adapters (ports)\n", n_ports); - for (signed int i=p1; isetVerboseLevel(getDebugLevel()); - if ( !tmp1394->initialize(i) ) { - delete tmp1394; - continue; - } - - if (arguments.node < 0) { - n1 = 0; - n2 = tmp1394->getNodeCount(); - } else { - // Scan a specific node if given on the command line - n1 = n2 = arguments.node; - n2++; - } - for (fb_nodeid_t node = n1; node < n2; node++) { - std::auto_ptr configRom = - std::auto_ptr( new ConfigRom(*tmp1394, node)); - if (!configRom->initialize()) { - continue; - } - // Assume anything with suitable vendor IDs is an audio device. - // Stop at the first audio device found. Currently we detect - // only MOTU devices but this can be expanded on an as-needs - // basis. - if (configRom->getNodeVendorId() == 0x1f2) { - node_id = node; - port = i; - break; - } - } - delete tmp1394; - } - if (node_id == -1) { - printf("Could not find a target audio device on the firewire bus\n"); - return false; - } - printf("Targetting device at port %d, node %d\n", port, node_id); - - Ieee1394Service *m_1394Service = new Ieee1394Service(); - if ( !m_1394Service ) { - debugFatal( "Could not create Ieee1349Service object\n" ); - return false; - } - m_1394Service->setVerboseLevel(getDebugLevel()); - if ( !m_1394Service->initialize(port) ) { - // This initialise call should never fail since it worked during the - // scan. We live in a strange world though, so trap the error - // anyway. - debugFatal("Could not initialise ieee1394 on MOTU port\n"); - delete m_1394Service; - return false; - } - - quadlet_t old_vals[arguments.scan_length/4+1], quadlet; - unsigned int present[arguments.scan_length/(4*32)+1]; - memset(old_vals, 0x00, sizeof(old_vals)); - // Assume all registers are present until proven otherwise - memset(present, 0xff, sizeof(present)); - - printf("Scanning initial register values, please wait\n"); - chr[0] = 0; - while(chr[0]!='q') { - for (signed int reg=arguments.scan_start; - regread(0xffc0 | node_id, MOTU_BASE_ADDR+reg, 1, &quadlet) <= 0) { - // Flag the register as not being present so we don't keep trying to read it - present[pres_index] &= ~(1< to scan, \"q\" to exit\n"); - fgets(chr, sizeof(chr), stdin); - loop++; - } - - delete m_1394Service; - - return 0; -} - Index: /anches/libffado-2.0/tests/test-streamdump.cpp =================================================================== --- /branches/libffado-2.0/tests/test-streamdump.cpp (revision 1146) +++ (revision ) @@ -1,209 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Daniel Wagner - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -#include -#include -#include - -using namespace std; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-streamdump 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-streamdump -- test program to get a BeBoB device to stream and to save the streams"; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - { 0 } -}; - -struct arguments -{ - arguments() - : verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[1]; - bool verbose; - bool test; - int port; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 1) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 1) { - // Not enough arguments. - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int iNodeId = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port ); - if ( !pHandle ) { - if ( !errno ) { - cerr << "libraw1394 not compatible" << endl; - } else { - perror( "Could not get 1394 handle" ); - cerr << "Is ieee1394 and raw1394 driver loaded?" << endl; - } - return -1; - } - - struct Connection { - int m_output; - int m_oplug; - int m_input; - int m_iplug; - int m_iBandwith; - int m_iIsoChannel; - }; - - - int iLocalId = raw1394_get_local_id( pHandle ); - int iRemoteId = iNodeId | 0xffc0; - Connection cons[] = { - // output, oplug, input, iplug, bandwith, iso channel - { iRemoteId, 0, iLocalId, -1, 0x148, -1 }, // oPCR[0] -// { iRemoteId, 1, iLocalId, -1, 0x148, -1 }, // oPCR[1] - // { iRemoteId, 2, iLocalId, -1, 0, -1 }, // oPCR[2]: cmp not supported -// { iLocalId, -1, iRemoteId, 0, 0x148, -1 }, // iPCR[0] -// { iLocalId, -1, iRemoteId, 1, 0x148, -1 }, // iPCR[1] - // { iLocalId, -1, iRemoteId, 2, 0, -1 }, // iPCR[2]: cmp not supported - }; - - printf( "local node id %d\n", iLocalId & ~0xffc0); - printf( "remote node id %d\n", iRemoteId & ~0xffc0); - - for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) { - Connection* pCons = &cons[i]; - - // the bandwith calculation fails, so its better to use - // some default values. - pCons->m_iBandwith = iec61883_cmp_calc_bandwidth ( pHandle, - pCons->m_output, - pCons->m_oplug, - IEC61883_DATARATE_400 ); - sleep(1); - pCons->m_iIsoChannel = iec61883_cmp_connect( pHandle, - pCons->m_output, - &pCons->m_oplug, - pCons->m_input, - &pCons->m_iplug, - &pCons->m_iBandwith ); - printf( "%2d -> %2d %cPCR[%2d]: bw = %4d, ch = %2d\n", - pCons->m_output & ~0xffc0, - pCons->m_input & ~0xffc0, - pCons->m_oplug == -1? 'i' : 'o', - pCons->m_oplug == -1? pCons->m_iplug: pCons->m_oplug, - pCons->m_iBandwith, - pCons->m_iIsoChannel ); - sleep(1); - } - - sleep( 5 ); - - for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) { - Connection* pCons = &cons[i]; - - if ( pCons->m_iIsoChannel != -1 ) { - printf( "disconnect\n"); - iec61883_cmp_disconnect( pHandle, - pCons->m_output, - pCons->m_oplug, - pCons->m_input, - pCons->m_iplug, - pCons->m_iIsoChannel, - pCons->m_iBandwith ); - - - } - } - - - raw1394_destroy_handle( pHandle ); - return 0; -} Index: /anches/libffado-2.0/tests/test-echomixer.cpp =================================================================== --- /branches/libffado-2.0/tests/test-echomixer.cpp (revision 1146) +++ (revision ) @@ -1,595 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -#include "debugmodule/debugmodule.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" -#include "libutil/cmd_serialize.h" -#include "libavc/general/avc_generic.h" - -#include "fireworks/efc/efc_avc_cmd.h" -#include "fireworks/efc/efc_cmds_mixer.h" -#include "fireworks/efc/efc_cmds_monitor.h" -#include "fireworks/efc/efc_cmds_hardware.h" -using namespace FireWorks; - -#include -#include -#include - -using namespace std; -using namespace AVC; -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 1000 - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-echomixer 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to examine the echo audio mixer."; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - {"node", 'n', "NODE", 0, "Set node" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - bool verbose; - bool test; - int port; - int node; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 'n': - arguments->node = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs<0) { - printf("not enough arguments\n"); - return -1; - } - - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -bool doEfcOverAVC(Ieee1394Service& m_1394Service, int node, EfcCmd &c) -{ - EfcOverAVCCmd cmd( m_1394Service ); - cmd.setCommandType( AVC::AVCCommand::eCT_Control ); - cmd.setNodeId( node ); - cmd.setSubunitType( AVC::eST_Unit ); - cmd.setSubunitId( 0xff ); - - cmd.setVerbose( DEBUG_LEVEL_NORMAL ); - - cmd.m_cmd = &c; - - if ( !cmd.fire()) { - debugError( "EfcOverAVCCmd command failed\n" ); - c.showEfcCmd(); - return false; - } - - if ( c.m_header.retval != EfcCmd::eERV_Ok - && c.m_header.retval != EfcCmd::eERV_FlashBusy) { - debugError( "EFC command failed\n" ); - c.showEfcCmd(); - return false; - } - - return true; -} - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - errno = 0; - - Ieee1394Service *m_1394Service = new Ieee1394Service(); - if ( !m_1394Service ) { - debugFatal( "Could not create Ieee1349Service object\n" ); - return false; - } - - if ( !m_1394Service->initialize( arguments.port ) ) { - debugFatal( "Could not initialize Ieee1349Service object\n" ); - delete m_1394Service; - m_1394Service = 0; - return false; - } - - EfcHardwareInfoCmd m_HwInfo; - - if (!doEfcOverAVC(*m_1394Service, arguments.node, m_HwInfo)) { - debugFatal("Could not obtain FireWorks device info\n"); - return false; - } - m_HwInfo.showEfcCmd(); - - unsigned int ch=0; - - uint32_t pbk_vol[m_HwInfo.m_nb_1394_playback_channels][5]; - uint32_t rec_vol[m_HwInfo.m_nb_1394_record_channels][5]; - uint32_t out_vol[m_HwInfo.m_nb_phys_audio_out][5]; - uint32_t in_vol[m_HwInfo.m_nb_phys_audio_in][5]; - - memset(pbk_vol, 0, sizeof(uint32_t) * 5 * m_HwInfo.m_nb_1394_playback_channels); - memset(rec_vol, 0, sizeof(uint32_t) * 5 * m_HwInfo.m_nb_1394_record_channels); - memset(out_vol, 0, sizeof(uint32_t) * 5 * m_HwInfo.m_nb_phys_audio_out); - memset(in_vol, 0, sizeof(uint32_t) * 5 * m_HwInfo.m_nb_phys_audio_in); - - enum eMixerTarget t=eMT_PlaybackMix; - enum eMixerCommand c = eMC_Gain; - enum eCmdType type = eCT_Get; - EfcGenericMixerCmd cmd(t,c); - cmd.setType(type); - -#define DO_PLAYBACK_MIX -// #define DO_RECORD_MIX -#define DO_PHYS_OUT_MIX -#define DO_PHYS_IN_MIX - -#ifdef DO_PLAYBACK_MIX - cmd.setTarget(eMT_PlaybackMix); - for (ch=0;ch. - * - */ - -#include "libavc/avc_function_block.h" -#include "libavc/avc_serialize.h" -#include "debugmodule/debugmodule.h" - -#include "libieee1394/ieee1394service.h" -#include - -DECLARE_GLOBAL_DEBUG_MODULE; - -const bool bVerbose = true; - -bool -doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Processing, - fb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Status ); - fbCmd.m_pFBProcessing->m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer; - - debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer programmable state...\n"); - - fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00; - fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0xff; - fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0xff; - fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector - = FunctionBlockProcessingEnhancedMixer::eSS_ProgramableState; - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - debugOutput(DEBUG_LEVEL_NORMAL, "Requesting mixer level state...\n"); - - fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00; - fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0x00; - fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0x00; - fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector - = FunctionBlockProcessingEnhancedMixer::eSS_Level; - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return true; -} - -bool -selectorGet( Ieee1394Service& ieee1394service, int node_id, int fb_id ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Selector, - fb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Status ); - fbCmd.m_pFBSelector->m_inputFbPlugNumber=0; - - debugOutput(DEBUG_LEVEL_NORMAL, "Requesting selector state...\n"); - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return true; -} - -bool -selectorSet( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Selector, - fb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Control ); - fbCmd.m_pFBSelector->m_inputFbPlugNumber=val; - - debugOutput(DEBUG_LEVEL_NORMAL, "Setting selector state to %d...\n", val); - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return true; -} - -bool -volumeGet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Feature, - fb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Status ); - fbCmd.m_pFBFeature->m_audioChannelNumber=channel; - fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; - fbCmd.m_pFBFeature->m_pVolume->m_volume=0; - - debugOutput(DEBUG_LEVEL_NORMAL, "Requesting volume feature block state...\n"); - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return true; -} - -bool -volumeSet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel, int value ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Feature, - fb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Control ); - fbCmd.m_pFBFeature->m_audioChannelNumber=channel; - fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; - fbCmd.m_pFBFeature->m_pVolume->m_volume=value; - - debugOutput(DEBUG_LEVEL_NORMAL, "Setting volume feature block channel %d state to %d...\n", channel, value); - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - debugError( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return true; -} - -/////////////////////////// -// main -////////////////////////// -int -main( int argc, char **argv ) -{ - - if (argc < 4) { - debugError("usage: PORT NODE_ID CMD FB_ID [VAL1] [VAL2]\n"); - exit(0); - } - - int errno = 0; - char* tail; - int port = strtol( argv[1], &tail, 0 ); - int node_id = strtol( argv[2], &tail, 0 ); - int cmd = strtol( argv[3], &tail, 0 ); - int fb_id = strtol( argv[4], &tail, 0 ); - - int value1=-1; - int value2=-1; - - if (argc>=6) - value1 = strtol(argv[5], &tail, 0 ); - - if (argc>=7) - value2 = strtol(argv[6], &tail, 0 ); - - if (errno) { - debugError("argument parsing failed: %s\n", strerror(errno)); - return -1; - } - Ieee1394Service ieee1394service; - if ( !ieee1394service.initialize( port ) ) { - debugError( "could not set port on ieee1394service\n" ); - return -1; - } - - switch(cmd) { - case 0: - doApp( ieee1394service, node_id, fb_id ); - break; - case 1: - selectorGet( ieee1394service, node_id, fb_id ); - break; - case 2: - selectorSet( ieee1394service, node_id, fb_id , value1 ); - break; - case 3: - volumeGet( ieee1394service, node_id, fb_id, value1); - break; - case 4: - volumeSet( ieee1394service, node_id, fb_id, value1, value2); - break; - } - - return 0; -} Index: /anches/libffado-2.0/tests/test-ipcringbuffer.cpp =================================================================== --- /branches/libffado-2.0/tests/test-ipcringbuffer.cpp (revision 1172) +++ (revision ) @@ -1,226 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "debugmodule/debugmodule.h" - -#include "libutil/IpcRingBuffer.h" -#include "libutil/SystemTimeSource.h" - -#include -#include -#include -#include - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 2 - -int run=1; -int lastsig=-1; -static void sighandler (int sig) -{ - run = 0; -} - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-ipcringbuffer 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to test the ipc ringbuffer class."; -static char args_doc[] = "DIRECTION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - long int verbose; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs <= 0) { - printMessage("not enough arguments\n"); - return -1; - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - - setDebugLevel(arguments.verbose); - - errno = 0; - char* tail; - long int direction = strtol( arguments.args[0], &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse direction argument\n" ); - exit(-1); - } - - printMessage("Testing shared memory direction %ld\n", direction); - - #define TEST_SAMPLERATE 44100 - #define BUFF_SIZE 64 - #define NB_BUFFERS 4 - IpcRingBuffer* b = NULL; - if(direction == 0) { - b = new IpcRingBuffer("testbuff", - IpcRingBuffer::eBT_Master, - IpcRingBuffer::eD_Outward, - IpcRingBuffer::eB_Blocking, - NB_BUFFERS, BUFF_SIZE); - if(b == NULL) { - debugError("Could not create master\n"); - exit(-1); - } - } else { - b = new IpcRingBuffer("testbuff", - IpcRingBuffer::eBT_Master, - IpcRingBuffer::eD_Inward, - IpcRingBuffer::eB_Blocking, - NB_BUFFERS, BUFF_SIZE); - if(b == NULL) { - debugError("Could not create master\n"); - exit(-1); - } - } - - b->setVerboseLevel(arguments.verbose); - - char buff[BUFF_SIZE]; - int cnt = 0; - long int time_to_sleep = 1000*1000*BUFF_SIZE/TEST_SAMPLERATE; - - if(!b->init()) { - debugError("Could not init buffer\n"); - goto out_err; - } - - run=1; - while(run) { - if(direction == 0) { - snprintf(buff, BUFF_SIZE, "test %d", cnt); - if(cnt%1000==0) { - printMessage("writing '%s'...\n", buff); - } - IpcRingBuffer::eResult res = b->Write(buff); - if(res != IpcRingBuffer::eR_OK && res != IpcRingBuffer::eR_Again) { - debugError("Could not write to segment\n"); - goto out_err; - } - if(res == IpcRingBuffer::eR_Again) { - printMessage(" Try again on %d...\n", cnt); - } else { - cnt++; - } - usleep(time_to_sleep); - } else { - if(cnt%1000==0) { - printMessage("reading...\n"); - } - - IpcRingBuffer::eResult res = b->Read(buff); - if(res != IpcRingBuffer::eR_OK && res != IpcRingBuffer::eR_Again) { - debugError("Could not receive from queue\n"); - goto out_err; - } - if(cnt%1000==0) { - buff[BUFF_SIZE-1]=0; - printMessage(" read: '%s'\n", buff); - } - if(res == IpcRingBuffer::eR_Again) { - printMessage(" Try again on %d...\n", cnt); - } else { - cnt++; - } - } - } - - delete b; - return 0; - -out_err: - delete b; - return -1; -} - Index: /anches/libffado-2.0/tests/test-enhanced-mixer.cpp =================================================================== --- /branches/libffado-2.0/tests/test-enhanced-mixer.cpp (revision 864) +++ (revision ) @@ -1,96 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "libavc/audiosubunit/avc_function_block.h" -#include "libutil/cmd_serialize.h" - -#include "libieee1394/ieee1394service.h" - -using namespace AVC; - -bool -doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id ) -{ - AVC::FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Processing, - fb_id, - FunctionBlockCmd::eCA_Current); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Status ); - fbCmd.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); - - // Ok, this enhanced mixer setting here is just a hack, we need - // a sane way to set processing features (read pointer management) - delete fbCmd.m_pFBProcessing->m_pMixer; - fbCmd.m_pFBProcessing->m_pMixer = 0; - AVC::FunctionBlockProcessingEnhancedMixer em; - fbCmd.m_pFBProcessing->m_pEnhancedMixer = em.clone(); - - fbCmd.m_pFBProcessing->m_fbInputPlugNumber = 0x00; - fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0xff; - fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0xff; - fbCmd.m_pFBProcessing->m_pEnhancedMixer->m_statusSelector = 1; - - if ( !fbCmd.fire() ) { - printf( "cmd failed\n" ); - return false; - } - - // Util::Cmd::CoutSerializer se; - // fbCmd.serialize( se ); - - return true; -} - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - - if (argc < 2) { - printf("usage: NODE_ID FB_ID\n"); - exit(0); - } - - int errno = 0; - char* tail; - int node_id = strtol( argv[1], &tail, 0 ); - int fb_id = strtol( argv[2], &tail, 0 ); - - if (errno) { - perror("argument parsing failed:"); - return -1; - } - Ieee1394Service ieee1394service; - if ( !ieee1394service.initialize( 0 ) ) { - fprintf( stderr, "could not set port on ieee1394service\n" ); - return -1; - } - - doApp( ieee1394service, node_id, fb_id ); - - return 0; -} Index: /anches/libffado-2.0/tests/test-shm.cpp =================================================================== --- /branches/libffado-2.0/tests/test-shm.cpp (revision 1172) +++ (revision ) @@ -1,200 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "debugmodule/debugmodule.h" - -#include "libutil/PosixSharedMemory.h" - -#include -#include -#include -#include - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 2 - -int run=1; -int lastsig=-1; -static void sighandler (int sig) -{ - run = 0; -} - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-shm 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to test the shared memory class."; -static char args_doc[] = "DIRECTION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - long int verbose; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs <= 0) { - printMessage("not enough arguments\n"); - return -1; - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - - setDebugLevel(arguments.verbose); - - errno = 0; - char* tail; - long int direction = strtol( arguments.args[0], &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse direction argument\n" ); - exit(-1); - } - - printMessage("Testing shared memory direction %ld\n", direction); - - PosixSharedMemory s = PosixSharedMemory("testseg", 1024); - s.setVerboseLevel(arguments.verbose); - - if(direction == 0) { - if(!s.Create(PosixSharedMemory::eD_ReadWrite)) { - debugError("Could not create segment\n"); - exit(-1); - } - } else { - if(!s.Open(PosixSharedMemory::eD_ReadOnly)) { - debugError("Could not open segment\n"); - exit(-1); - } - } - - if(!s.LockInMemory(true)) { - debugError("Could not memlock segment\n"); - } - - int offset=0; - int len = 64; - char buff[len]; - - int cnt = 0; - run=1; - long int time_to_sleep = 1000*1000; - while(run) { - if(direction == 0) { - snprintf(buff, len, "test %d", cnt++); - printMessage("writing '%s'...\n", buff); - if(s.Write(offset, buff, len) != PosixSharedMemory::eR_OK) { - debugError("Could not write to segment\n"); - goto out_err; - } - usleep(time_to_sleep); - } else { - printMessage("reading...\n"); - if(s.Read(offset, buff, len) != PosixSharedMemory::eR_OK) { - debugError("Could not receive from queue\n"); - goto out_err; - } - buff[len-1]=0; - printMessage(" read: '%s'\n", buff); - usleep(time_to_sleep * 110/100); - } - } - - if(!s.LockInMemory(false)) { - debugError("Could not mem-unlock segment\n"); - } - - return 0; - -out_err: - if(!s.LockInMemory(false)) { - debugError("Could not mem-unlock segment\n"); - } - return -1; -} - Index: /anches/libffado-2.0/tests/test-messagequeue.cpp =================================================================== --- /branches/libffado-2.0/tests/test-messagequeue.cpp (revision 1172) +++ (revision ) @@ -1,284 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "debugmodule/debugmodule.h" - -#include "libutil/PosixMessageQueue.h" -#include "libutil/Functors.h" - -#include -#include -#include -#include - -#include - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 2 - -int run=1; -int lastsig=-1; -static void sighandler (int sig) -{ - run = 0; -} - -sem_t peep_sem; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-messagequeue 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to test the message queues."; -static char args_doc[] = "DIRECTION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - long int verbose; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs <= 0) { - printMessage("not enough arguments\n"); - return -1; - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -class TestMessage : public Util::PosixMessageQueue::Message -{ -public: - TestMessage() - : Message() - , m_prio( 0 ) - , m_length( 64 ) - , m_cnt( 0 ) - {}; - virtual ~TestMessage() - {}; - - virtual unsigned int getPriority() - {return m_prio;}; - virtual unsigned int getLength() { - return m_length; - }; - - virtual bool serialize(char *buff) { - snprintf(buff, m_length, "cnt: %d", m_cnt++); - return true; - } - - virtual bool deserialize(const char *buff, unsigned int length, unsigned prio) { - char tmp[length+1]; - snprintf(tmp, length, "%s", buff); - tmp[length]=0; - printMessage("got message: '%s', prio %u\n", tmp, prio); - m_prio = prio; - return true; - }; - -private: - unsigned m_prio; - unsigned int m_length; - int m_cnt; -}; - -void peep() { - printMessage("peep...\n"); - sem_post(&peep_sem); -} - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - int rv=0; - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - - setDebugLevel(arguments.verbose); - - errno = 0; - char* tail; - long int direction = strtol( arguments.args[0], &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse direction argument\n" ); - exit(-1); - } - - if(sem_init(&peep_sem, 0, 0)) { - debugError("Could not init wait sem\n"); - exit(-1); - } - - printMessage("Testing message queue direction %ld\n", direction); - - Util::Functor* peepfunc = NULL; - - PosixMessageQueue p = PosixMessageQueue("testqueue1"); - p.setVerboseLevel(arguments.verbose); - if(direction == 0) { - if(!p.Create(PosixMessageQueue::eD_WriteOnly)) { - debugError("Could not create queue\n"); - exit(-1); - } - } else { - if(!p.Open(PosixMessageQueue::eD_ReadOnly, PosixMessageQueue::eB_NonBlocking)) { - debugError("Could not open queue\n"); - exit(-1); - } - peepfunc = new Util::CallbackFunctor0< void (*)() > - ( &peep, false ); - if ( !peepfunc ) { - debugError( "Could not create peep handler\n" ); - exit(-1); - } - if(!p.setNotificationHandler(peepfunc)) { - debugError("Could not set Notification Handler\n"); - exit(-1); - } -// if(!p.enableNotification()) { -// debugError("Could not enable Notification\n"); -// exit(-1); -// } - } - - #define TIME_TO_SLEEP 1000*100 - TestMessage m = TestMessage(); - //m.setVerboseLevel(arguments.verbose); - run=1; - while(run) { - if(direction == 0) { - printMessage("sending...\n"); - if(p.Send(m) != PosixMessageQueue::eR_OK) { - debugError("Could not send to queue\n"); - goto out_err; - } - usleep(TIME_TO_SLEEP); - } else { - printMessage("receiving...\n"); - printMessage(" enable notification...\n"); - // first enable notification - if(!p.enableNotification()) { - debugError("Could not enable Notification\n"); - goto out_err; - } - // then read all there is to read - printMessage(" reading...\n"); - enum PosixMessageQueue::eResult ret; - while((ret = p.Receive(m)) == PosixMessageQueue::eR_OK) { - // nothing - } - if (ret != PosixMessageQueue::eR_OK && ret != PosixMessageQueue::eR_Again) { - debugError("Could not receive from queue\n"); - goto out_err; - } - // wait for a notification - printMessage(" waiting...\n"); - if(sem_wait(&peep_sem)) { - printMessage(" error: %s\n", strerror(errno)); - goto out_err; - } - } - } - -cleanup: - if(peepfunc) { - if(!p.disableNotification()) { - debugError("Could not disable Notification\n"); - } - if(!p.unsetNotificationHandler()) { - debugError("Could not unset Notification Handler\n"); - exit(-1); - } - delete peepfunc; - } - - sem_destroy(&peep_sem); - return rv; - -out_err: - rv=-1; - goto cleanup; - -} - Index: /anches/libffado-2.0/tests/test-bufferops.cpp =================================================================== --- /branches/libffado-2.0/tests/test-bufferops.cpp (revision 1136) +++ (revision ) @@ -1,270 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "debugmodule/debugmodule.h" - -DECLARE_GLOBAL_DEBUG_MODULE; - -#include "libutil/ByteSwap.h" -#include "libstreaming/amdtp/AmdtpBufferOps.h" - -#include "libutil/SystemTimeSource.h" -#include - -// 32M of test data -#define NB_QUADLETS (1024 * 1024 * 32) -#define NB_TESTS 10 - -bool -testByteSwap(int nb_quadlets, int nb_tests) { - quadlet_t *buffer_1; - quadlet_t *buffer_ref; - int i=0; - - ffado_microsecs_t start; - ffado_microsecs_t elapsed; - - setDebugLevel(DEBUG_LEVEL_NORMAL); - - buffer_1 = new quadlet_t[nb_quadlets]; - buffer_ref = new quadlet_t[nb_quadlets]; - - printMessage( "Generating test data...\n"); - for (i=0; i> 8 ) | 0x40000000; - buffer_ref[i] = tmp; - } - - printMessage( "Performing AMDTP labeling...\n"); - - int test=0; - for (test=0; test. - * - */ - -#include -#include - -#include "debugmodule/debugmodule.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" -#include "libutil/cmd_serialize.h" -#include "libavc/general/avc_generic.h" - -#include -#include -#include - -using namespace std; -using namespace AVC; -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 1000 - -class TestCmd: public AVCCommand -{ -public: - TestCmd(Ieee1394Service& ieee1394service, opcode_t opcode ); - virtual ~TestCmd(); - - virtual bool serialize( Util::Cmd::IOSSerialize& se ); - virtual bool deserialize( Util::Cmd::IISDeserialize& de ); - - virtual const char* getCmdName() const - { return "TestCmd"; } - - byte_t args[MAX_ARGS]; - int nargs; -}; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-avccmd 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to send a custom avc command to a specific node."; -static char args_doc[] = "NODE_ID [avc cmd byte sequence]"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - {"node", 'n', "NODE", 0, "Set node" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - bool verbose; - bool test; - int port; - int node; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 'n': - arguments->node = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs<4) { - printf("not enough arguments\n"); - return -1; - } - - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - errno = 0; - char* tail; - - - Ieee1394Service *m_1394Service = new Ieee1394Service(); - if ( !m_1394Service ) { - debugFatal( "Could not create Ieee1349Service object\n" ); - return false; - } - - if ( !m_1394Service->initialize( arguments.port ) ) { - debugFatal( "Could not initialize Ieee1349Service object\n" ); - delete m_1394Service; - m_1394Service = 0; - return false; - } - - char cmdtype = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - char unit_subunit = strtol(arguments.args[1], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - opcode_t opcode = strtol(arguments.args[2], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - TestCmd cmd( *m_1394Service, opcode ); - switch (cmdtype) { - case AVC::AVCCommand::eCT_Control: cmd.setCommandType( AVC::AVCCommand::eCT_Control ); break; - case AVC::AVCCommand::eCT_Status: cmd.setCommandType( AVC::AVCCommand::eCT_Status ); break; - case AVC::AVCCommand::eCT_SpecificInquiry: cmd.setCommandType( AVC::AVCCommand::eCT_SpecificInquiry ); break; - case AVC::AVCCommand::eCT_Notify: cmd.setCommandType( AVC::AVCCommand::eCT_Notify ); break; - case AVC::AVCCommand::eCT_GeneralInquiry: cmd.setCommandType( AVC::AVCCommand::eCT_GeneralInquiry ); break; - default: printf("Invalid command type: 0x%02X.\n", cmdtype); exit(-1); - } - cmd.setNodeId( arguments.node ); - - cmd.setSubunitType( byteToSubunitType(unit_subunit >> 3) ); - cmd.setSubunitId( (unit_subunit & 0x7) ); - - cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE ); - - int i=0; - - for (;i. - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include -#include "src/debugmodule/debugmodule.h" - -#include "libutil/PosixThread.h" -#include "libutil/Watchdog.h" -#include "libutil/SystemTimeSource.h" - -#include - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -class HangTask : public Util::RunnableInterface -{ -public: - HangTask(unsigned int time_usecs, unsigned int nb_hangs) - : m_time( time_usecs ) - , m_nb_hangs(nb_hangs) {}; - virtual ~HangTask() {}; - - bool Init() {return true;}; - bool Execute() { - debugOutput(DEBUG_LEVEL_VERBOSE, "execute\n"); - ffado_microsecs_t start = Util::SystemTimeSource::getCurrentTimeAsUsecs(); - ffado_microsecs_t stop_at = start + m_time; - int cnt; - int dummyvar = 0; - while(Util::SystemTimeSource::getCurrentTimeAsUsecs() < stop_at) { - cnt=1000; - while(cnt--) { dummyvar++; } - } - - // ensure that dummyvar doesn't get optimized away - bool always_true = (dummyvar + Util::SystemTimeSource::getCurrentTimeAsUsecs() != 0); - - bool stop = (m_nb_hangs == 0); - m_nb_hangs--; - - // we sleep for 100ms after a 'hang' - Util::SystemTimeSource::SleepUsecRelative(1000*100); - - // we want the thread to exit after m_nb_hangs 'hangs' - return always_true && !stop; - }; - unsigned int m_time; - unsigned int m_nb_hangs; - -}; - -int run; -// Program documentation. -static char doc[] = "FFADO -- Watchdog test\n\n"; - -// A description of the arguments we accept. -static char args_doc[] = ""; - - -struct arguments -{ - short verbose; -}; - -// The options we understand. -static struct argp_option options[] = { - {"verbose", 'v', "n", 0, "Verbose level" }, - { 0 } -}; - -//------------------------------------------------------------- - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - char* tail; - - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -// Our argp parser. -static struct argp argp = { options, parse_opt, args_doc, doc }; - - -static void sighandler (int sig) -{ - run = 0; -} - -int main(int argc, char *argv[]) -{ - - Watchdog *w=NULL; - - struct arguments arguments; - - // Default values. - arguments.verbose = DEBUG_LEVEL_VERY_VERBOSE; - - // Parse our arguments; every option seen by `parse_opt' will - // be reflected in `arguments'. - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(1); - } - - setDebugLevel(arguments.verbose); - - run=1; - - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - w=new Watchdog(1000*1000*1, true, 99); // check time is one second - w->setVerboseLevel(arguments.verbose); - - HangTask *task1=new HangTask(1000*10, 10); // ten millisecond, 10 hangs - PosixThread *thread1 = new Util::PosixThread(task1, true, 10, PTHREAD_CANCEL_DEFERRED); - thread1->setVerboseLevel(arguments.verbose); - - HangTask *task2=new HangTask(1000*1000*2, 10); // two seconds, 10 hangs - PosixThread *thread2 = new Util::PosixThread(task2, true, 10, PTHREAD_CANCEL_DEFERRED); - thread2->setVerboseLevel(arguments.verbose); - - w->registerThread(thread1); - w->registerThread(thread2); - - // start the watchdog - w->start(); - Util::SystemTimeSource::SleepUsecRelative(1000*1000*1); - - // start the first thread, should be harmless since it's hang time is too low - thread1->Start(); - Util::SystemTimeSource::SleepUsecRelative(1000*1000*1); - - // start the second thread, should be rescheduled since it hangs too long - thread2->Start(); - - // wait for a while - Util::SystemTimeSource::SleepUsecRelative(1000*1000*5); - - - thread1->Stop(); - thread2->Stop(); - - w->unregisterThread(thread1); - w->unregisterThread(thread2); - - delete thread1; - delete thread2; - delete task1; - delete task2; - delete w; - - return EXIT_SUCCESS; -} - - Index: /anches/libffado-2.0/tests/test-fw410.cpp =================================================================== --- /branches/libffado-2.0/tests/test-fw410.cpp (revision 864) +++ (revision ) @@ -1,207 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -#include -#include -#include - -using namespace std; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-fw410 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-fw410 -- test program to get the fw410 streaming"; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - { 0 } -}; - -struct arguments -{ - arguments() - : verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[1]; - bool verbose; - bool test; - int port; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - errno = 0; - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 1) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 1) { - // Not enough arguments. - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int iNodeId = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port ); - if ( !pHandle ) { - if ( !errno ) { - cerr << "libraw1394 not compatible" << endl; - } else { - perror( "Could not get 1394 handle" ); - cerr << "Is ieee1394 and raw1394 driver loaded?" << endl; - } - return -1; - } - - struct Connection { - int m_output; - int m_oplug; - int m_input; - int m_iplug; - int m_iBandwith; - int m_iIsoChannel; - }; - - - int iLocalId = raw1394_get_local_id( pHandle ); - int iRemoteId = iNodeId | 0xffc0; - Connection cons[] = { - // output, oplug, input, iplug, bandwith, iso channel - { iRemoteId, 0, iLocalId, -1, 0x148, -1 }, // oPCR[0] - { iRemoteId, 1, iLocalId, -1, 0x148, -1 }, // oPCR[1] - // { iRemoteId, 2, iLocalId, -1, 0, -1 }, // oPCR[2]: cmp not supported - { iLocalId, -1, iRemoteId, 0, 0x148, -1 }, // iPCR[0] - { iLocalId, -1, iRemoteId, 1, 0x148, -1 }, // iPCR[1] - // { iLocalId, -1, iRemoteId, 2, 0, -1 }, // iPCR[2]: cmp not supported - }; - - printf( "local node id %d\n", iLocalId & ~0xffc0); - printf( "remote node id %d\n", iRemoteId & ~0xffc0); - - for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) { - Connection* pCons = &cons[i]; - - // the bandwith calculation fails, so its better to use - // some default values. - pCons->m_iBandwith = iec61883_cmp_calc_bandwidth ( pHandle, - pCons->m_output, - pCons->m_oplug, - IEC61883_DATARATE_400 ); - sleep(1); - pCons->m_iIsoChannel = iec61883_cmp_connect( pHandle, - pCons->m_output, - &pCons->m_oplug, - pCons->m_input, - &pCons->m_iplug, - &pCons->m_iBandwith ); - printf( "%2d -> %2d %cPCR[%2d]: bw = %4d, ch = %2d\n", - pCons->m_output & ~0xffc0, - pCons->m_input & ~0xffc0, - pCons->m_oplug == -1? 'i' : 'o', - pCons->m_oplug == -1? pCons->m_iplug: pCons->m_oplug, - pCons->m_iBandwith, - pCons->m_iIsoChannel ); - sleep(1); - } - - sleep( 3 ); - - for ( unsigned int i = 0; i < sizeof( cons ) / sizeof( cons[0] ); ++i ) { - Connection* pCons = &cons[i]; - - if ( pCons->m_iIsoChannel != -1 ) { - iec61883_cmp_disconnect( pHandle, - pCons->m_output, - pCons->m_oplug, - pCons->m_input, - pCons->m_iplug, - pCons->m_iIsoChannel, - pCons->m_iBandwith ); - - - } - } - - - raw1394_destroy_handle( pHandle ); - return 0; -} Index: /anches/libffado-2.0/tests/dumpiso_mod.cpp =================================================================== --- /branches/libffado-2.0/tests/dumpiso_mod.cpp (revision 1136) +++ (revision ) @@ -1,306 +1,0 @@ -/* - * libraw1394 - library for raw access to the 1394 bus with the Linux subsystem. - * - * Copyright (C) 1999,2000 Andreas Bombe - * - * This library is licensed under the GNU Lesser General Public License (LGPL), - * version 2.1 or later. See the file COPYING.LIB in the distribution for - * details. - */ - -#include -#include -#include -#include -#include -#include - -#include - -#include "src/libieee1394/cycletimer.h" -#include "src/debugmodule/debugmodule.h" -#include "src/libstreaming/util/cip.h" -#include "libutil/ByteSwap.h" - -#define BUFFER 1000 -#define PACKET_MAX 4096 - -// one 32 bit value as marker for start and stop -#define PACKET_START_MARKER 0x01020304 -#define PACKET_STOP_MARKER 0x04030201 - -u_int64_t listen_channels; -unsigned long which_port; -char *filename; -int file; -enum raw1394_iso_dma_recv_mode mode = RAW1394_DMA_DEFAULT; - -DECLARE_GLOBAL_DEBUG_MODULE; - -raw1394handle_t global_handle; - -void usage_exit(int exitcode) -{ - fprintf(stderr, -"Usage: dumpiso [opts] [FILE]\n" -"Dump IEEE 1394 isochronous channels to FILE or standard output.\n" -"\n" -"-c --channels CHANNELS Listen on these channels; CHANNELS is either a\n" -" number X or a range X-Y.\n" -"-p --port PORT Choose 1394 chip PORT. (default: 0)\n" -"-h --help Show this help.\n" -); - - exit(exitcode); -} - -void parse_args(int argc, char **argv) -{ - char *tail; - unsigned long i, chan1, chan2; - - int c; - int index; - static struct option opts[] = { - { "channels", required_argument, NULL, 'c' }, - { "port", required_argument, NULL, 'p' }, - { "help", no_argument, NULL, 'h' }, - { 0 } - }; - - while (1) { - c = getopt_long(argc, argv, "hc:p:", opts, &index); - if (c == -1) break; - - switch (c) { - case 'c': - chan1 = strtoul(optarg, &tail, 10); - chan2 = chan1; - - if (*tail) { - if (tail[0] != '-' || !tail[1]) { - fprintf(stderr, - "invalid argument to channels: %s\n", - optarg); - usage_exit(1); - } - - tail++; - chan2 = strtoul(tail, &tail, 10); - if (*tail) { - fprintf(stderr, - "invalid argument to channels: %s\n", - optarg); - usage_exit(1); - } - } else { - mode = RAW1394_DMA_PACKET_PER_BUFFER; - } - - if (chan2 < chan1) { - unsigned long x = chan1; - chan1 = chan2; - chan2 = x; - } - - if (chan2 > 63) { - fprintf(stderr, - "invalid channel numbers: %s\n", - optarg); - exit(1); - } - - for (i = chan1; i <= chan2; i++) - listen_channels |= 1ULL << i; - - break; - case 'p': - which_port = strtoul(optarg, &tail, 10); - if (*tail) { - fprintf(stderr, - "invalid argument to port: %s\n", - optarg); - usage_exit(1); - } - break; - case 'h': - usage_exit(0); - case '?': - usage_exit(1); - default: - abort(); - } - } - - argv += optind; - argc -= optind; - - if (argc > 1) { - fprintf(stderr, "Too many arguments.\n"); - usage_exit(1); - } - - if (argc) filename = *argv; - - if (!listen_channels) listen_channels = ~0ULL; -} - -void write_header() -{ - static char header[32] = "1394 isodump v3"; - int i; - - for (i = 0; i < 8; i++) - header[i+16] = (listen_channels >> (56 - 8*i)) & 0xff; - - i = 0; - while (i < 32) { - int ret; - ret = write(file, header + i, 32 - i); - - if (ret < 0) { - perror("header write"); - exit(1); - } - - i += ret; - } -} - -void open_dumpfile() -{ - if (!filename || !filename[0] || (filename[0] == '-' && !filename[1])) { - file = fileno(stdout); - write_header(); - return; - } - - file = open(filename, O_CREAT | O_WRONLY, 0666); - if (file < 0) { - perror("dumpfile open"); - exit(1); - } - - ftruncate(file, 0); - write_header(); -} - -static enum raw1394_iso_disposition -iso_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) -{ - int ret; - static unsigned int counter = 0; - uint32_t cycle_timer; - uint64_t local_time; - struct iec61883_packet *packet = (struct iec61883_packet *) data; - - if (++counter % 1000 == 0) - fprintf(stderr, "\r%uK packets", counter/1000); - - raw1394_read_cycle_timer(global_handle, &cycle_timer, &local_time); - - uint32_t timestamp = 0; - bool ok = (packet->syt != 0xFFFF) && - (packet->fdf != 0xFF) && - (packet->fmt == 0x10) && - (packet->dbs > 0) && - (length >= 2*sizeof(quadlet_t)); - if(ok) { - timestamp = sytRecvToFullTicks((uint32_t)CondSwapFromBus16(packet->syt), - cycle, cycle_timer); - } - /* write header */ - unsigned short length2 = length; - unsigned short cycle2 = cycle; - unsigned int marker = PACKET_START_MARKER; - write(file, &marker, 4); - write(file, &length2, sizeof(length2)); - write(file, &cycle2, sizeof(cycle2)); - write(file, &channel, sizeof(channel)); - write(file, &cycle_timer, sizeof(cycle_timer)); - write(file, ×tamp, sizeof(timestamp)); - write(file, &tag, sizeof(tag)); - write(file, &sy, sizeof(sy)); - sy = 0; - write(file, &sy, sizeof(sy)); - - while (length) { - ret = write(file, data, length); - if (ret < 0) { - perror("data write"); - return RAW1394_ISO_ERROR; - } - - length -= ret; - data += ret; - } - marker = PACKET_STOP_MARKER; - write(file, &marker, 4); - - return RAW1394_ISO_OK; -} - -int main(int argc, char **argv) -{ - raw1394handle_t handle; - int i; - - parse_args(argc, argv); - - fprintf(stderr, "port: %ld\nchannels: %#016llx\nfile: %s\n", which_port, - (long long unsigned int)(listen_channels), filename); - - handle = raw1394_new_handle(); - if (!handle) { - if (!errno) - fprintf(stderr, - "No working kernel driver found.\n"); - else - perror("raw1394_get_handle"); - exit(1); - } - - do { - if ((unsigned long)(raw1394_get_port_info(handle, NULL, 0)) <= which_port) { - fprintf(stderr, "Port %ld does not exist.\n", - which_port); - exit(1); - } - - raw1394_set_port(handle, which_port); - } while (errno == ESTALE); - - if (errno) { - perror("raw1394_set_port"); - exit(1); - } - - global_handle = raw1394_new_handle(); - raw1394_set_port(global_handle, which_port); - - open_dumpfile(); - - if (mode == RAW1394_DMA_DEFAULT) { - raw1394_iso_multichannel_recv_init(handle, iso_handler, - BUFFER, 2048, -1); /* >2048 makes rawiso stall! */ - raw1394_iso_recv_set_channel_mask(handle, listen_channels); - - } else for (i = 0; i < 64; i++) { - if (!(listen_channels & 1ULL << i)) - continue; - raw1394_iso_recv_init(handle, iso_handler, BUFFER, PACKET_MAX, - i, mode, -1); - } - raw1394_iso_recv_start(handle, -1, -1, 0); - - while (raw1394_loop_iterate(handle) == 0); - - fprintf(stderr, "\n"); - raw1394_iso_shutdown(handle); - raw1394_destroy_handle(handle); - - return 0; -} Index: /anches/libffado-2.0/tests/test-focusrite.cpp =================================================================== --- /branches/libffado-2.0/tests/test-focusrite.cpp (revision 1184) +++ (revision ) @@ -1,201 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include - -#include "debugmodule/debugmodule.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" -#include "libutil/cmd_serialize.h" -#include "libavc/general/avc_generic.h" -#include "libutil/Time.h" - -#include "bebob/focusrite/focusrite_cmd.h" -using namespace BeBoB::Focusrite; - -#include -#include -#include - -using namespace std; -using namespace AVC; -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define MAX_ARGS 1000 - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-focusrite 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-avccmd -- test program to examine the focusrite vendor dependent commands."; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - {"node", 'n', "NODE", 0, "Set node" }, - { 0 } -}; - -struct arguments -{ - arguments() - : nargs ( 0 ) - , verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[MAX_ARGS]; - int nargs; - bool verbose; - bool test; - int port; - int node; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 'n': - arguments->node = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= MAX_ARGS) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - arguments->nargs++; - break; - case ARGP_KEY_END: - if(arguments->nargs<4) { - printf("not enough arguments\n"); - return -1; - } - - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(-1); - } - errno = 0; - - Ieee1394Service *m_1394Service = new Ieee1394Service(); - if ( !m_1394Service ) { - debugFatal( "Could not create Ieee1349Service object\n" ); - return false; - } - - if ( !m_1394Service->initialize( arguments.port ) ) { - debugFatal( "Could not initialize Ieee1349Service object\n" ); - delete m_1394Service; - m_1394Service = 0; - return false; - } - - FocusriteVendorDependentCmd cmd( *m_1394Service ); - cmd.setVerbose( DEBUG_LEVEL_NORMAL ); - - #define TOTAL_IDS_TO_SCAN 128 - uint32_t old_vals[TOTAL_IDS_TO_SCAN+1]; - - while(1) { - for (int id=0; id. - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "debugmodule/debugmodule.h" - -#include "src/DeviceStringParser.h" - -DECLARE_GLOBAL_DEBUG_MODULE; - -// Program documentation. -static char doc[] = "FFADO -- Watchdog test\n\n"; - -// A description of the arguments we accept. -static char args_doc[] = ""; - - -struct arguments -{ - short verbose; -}; - -// The options we understand. -static struct argp_option options[] = { - {"verbose", 'v', "n", 0, "Verbose level" }, - { 0 } -}; - -//------------------------------------------------------------- - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - char* tail; - - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -// Our argp parser. -static struct argp argp = { options, parse_opt, args_doc, doc }; - -int main(int argc, char *argv[]) -{ - - struct arguments arguments; - - // Default values. - arguments.verbose = DEBUG_LEVEL_VERY_VERBOSE; - - // Parse our arguments; every option seen by `parse_opt' will - // be reflected in `arguments'. - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(1); - } - - setDebugLevel(arguments.verbose); - - DeviceStringParser p = DeviceStringParser(); - p.setVerboseLevel(arguments.verbose); - - p.parseString("hw:0;hw:1"); - p.parseString("hw:0;hw:1;"); - p.parseString("hw:0,0;hw:1,1;"); - p.parseString("hw:1,1;hw:1,0"); - p.parseString("guid:0x123456789"); - p.show(); - - return EXIT_SUCCESS; -} - - Index: /anches/libffado-2.0/tests/test-timestampedbuffer.cpp =================================================================== --- /branches/libffado-2.0/tests/test-timestampedbuffer.cpp (revision 1146) +++ (revision ) @@ -1,592 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include -#include "src/debugmodule/debugmodule.h" - -#include "libutil/ByteSwap.h" - -#include "src/libieee1394/cycletimer.h" - -#include "src/libutil/TimestampedBuffer.h" -#include "libutil/Time.h" - -#include - -using namespace Util; - -class TimestampedBufferTestClient - : public TimestampedBufferClient { -public: - bool processReadBlock(char *data, unsigned int nevents, unsigned int offset) {return true;}; - bool processWriteBlock(char *data, unsigned int nevents, unsigned int offset) {return true;}; - - void setVerboseLevel(int l) {setDebugLevel(l);}; -private: - DECLARE_DEBUG_MODULE; -}; - -IMPL_DEBUG_MODULE( TimestampedBufferTestClient, TimestampedBufferTestClient, DEBUG_LEVEL_VERBOSE ); - -DECLARE_GLOBAL_DEBUG_MODULE; - -int run; -// Program documentation. -static char doc[] = "FFADO -- Timestamped buffer test\n\n"; - -// A description of the arguments we accept. -static char args_doc[] = ""; - - -struct arguments -{ - short verbose; - uint64_t wrap_at; - uint64_t frames_per_packet; - uint64_t events_per_frame; - float rate; - uint64_t total_cycles; - uint64_t buffersize; - uint64_t start_at_cycle; -}; - -// The options we understand. -static struct argp_option options[] = { - {"verbose", 'v', "n", 0, "Verbose level" }, - {"wrap", 'w', "n", 0, "Wrap at (ticks) (3072000)" }, - {"fpp", 'f', "n", 0, "Frames per packet (8)" }, - {"epf", 'e', "n", 0, "Events per frame (10)" }, - {"rate", 'r', "n", 0, "Rate (ticks/frame) (512.0)" }, - {"cycles", 'c', "n", 0, "Total cycles to run (2000)" }, - {"buffersize", 'b', "n", 0, "Buffer size (in frames) (1024)" }, - {"startcycle", 's', "n", 0, "Start at cycle (0)" }, - { 0 } -}; - -//------------------------------------------------------------- - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - char* tail; - - errno = 0; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'w': - if (arg) { - arguments->wrap_at = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'wrap' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'wrap' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'f': - if (arg) { - arguments->frames_per_packet = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'fpp' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'fpp' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'e': - if (arg) { - arguments->events_per_frame = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'epf' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'epf' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'c': - if (arg) { - arguments->total_cycles = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'cycles' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'cycles' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 's': - if (arg) { - arguments->start_at_cycle = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'startcycle' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'startcycle' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'b': - if (arg) { - arguments->buffersize = strtoll( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'buffersize' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'buffersize' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'r': - if (arg) { - arguments->rate = strtof( arg, &tail ); - if ( errno ) { - fprintf( stderr, "Could not parse 'rate' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } else { - if ( errno ) { - fprintf( stderr, "Could not parse 'rate' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -// Our argp parser. -static struct argp argp = { options, parse_opt, args_doc, doc }; - - -static void sighandler (int sig) -{ - run = 0; -} - -int main(int argc, char *argv[]) -{ - - TimestampedBuffer *t=NULL; - TimestampedBufferTestClient *c=NULL; - - struct arguments arguments; - - // Default values. - arguments.verbose = 0; - arguments.wrap_at = 3072000LLU; // 1000 cycles - arguments.frames_per_packet = 8; - arguments.events_per_frame = 10; - arguments.rate = 512.0; - arguments.total_cycles = 2000; - arguments.buffersize = 1024; - arguments.start_at_cycle = 0; - - // Parse our arguments; every option seen by `parse_opt' will - // be reflected in `arguments'. - if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { - fprintf( stderr, "Could not parse command line\n" ); - exit(1); - } - - setDebugLevel(arguments.verbose); - - run=1; - - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - c=new TimestampedBufferTestClient(); - - if(!c) { - debugOutput(DEBUG_LEVEL_NORMAL, "Could not create TimestampedBufferTestClient\n"); - exit(1); - } - c->setVerboseLevel(arguments.verbose); - - t=new TimestampedBuffer(c); - - if(!t) { - debugOutput(DEBUG_LEVEL_NORMAL, "Could not create TimestampedBuffer\n"); - delete c; - exit(1); - } - t->setVerboseLevel(arguments.verbose); - - // Setup the buffer - t->setBufferSize(arguments.buffersize); - t->setEventSize(sizeof(int)); - t->setEventsPerFrame(arguments.events_per_frame); - - t->setUpdatePeriod(arguments.frames_per_packet); - t->setNominalRate(arguments.rate); - - t->setWrapValue(arguments.wrap_at); - - t->prepare(); - - SleepRelativeUsec(1000); - - debugOutput(DEBUG_LEVEL_NORMAL, "Start setBufferHeadTimestamp test...\n"); - { - bool pass=true; - uint64_t time=arguments.start_at_cycle*3072; - int dummyframe_in[arguments.events_per_frame*arguments.frames_per_packet]; - - // initialize the timestamp - uint64_t timestamp=time; - if (timestamp >= arguments.wrap_at) { - // here we need a modulo because start_at_cycle can be large - timestamp %= arguments.wrap_at; - } - - // account for the fact that there is offset, - // and that setBufferHeadTimestamp doesn't take offset - // into account - uint64_t timestamp2=timestamp; - if (timestamp2>=arguments.wrap_at) { - timestamp2-=arguments.wrap_at; - } - - t->setBufferHeadTimestamp(timestamp2); - - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - - // write some packets - for (unsigned int i=0;i<20;i++) { - t->writeFrames(arguments.frames_per_packet, (char *)&dummyframe_in, timestamp); - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - } - - for(unsigned int cycle=arguments.start_at_cycle; - cycle < arguments.start_at_cycle+arguments.total_cycles; - cycle++) { - ffado_timestamp_t ts_head_tmp; - uint64_t ts_head; - signed int fc_head; - - t->setBufferHeadTimestamp(timestamp); - t->getBufferHeadTimestamp(&ts_head_tmp, &fc_head); - ts_head=(uint64_t)ts_head_tmp; - - if (timestamp != ts_head) { - debugError(" cycle %4u error: %011llu != %011llu\n", - timestamp, ts_head); - pass=false; - } - - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - - // simulate the cycle timer clock in ticks - time += 3072; - if (time >= arguments.wrap_at) { - time -= arguments.wrap_at; - } - - // allow for the messagebuffer thread to catch up - SleepRelativeUsec(200); - - if(!run) break; - } - - if(!pass) { - debugError("Test failed, exiting...\n"); - - delete t; - delete c; - - return -1; - - } - } - - - - debugOutput(DEBUG_LEVEL_NORMAL, "Start read/write test...\n"); - { - int dummyframe_in[arguments.events_per_frame*arguments.frames_per_packet]; - int dummyframe_out[arguments.events_per_frame*arguments.frames_per_packet]; - - for (unsigned int i=0;i= arguments.wrap_at) { - // here we need a modulo because start_at_cycle can be large - timestamp %= arguments.wrap_at; - } - t->setBufferTailTimestamp(timestamp); - - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - - for(unsigned int cycle=arguments.start_at_cycle; - cycle < arguments.start_at_cycle+arguments.total_cycles; - cycle++) { - - // simulate the rate adaptation - int64_t diff=(time%arguments.wrap_at)-timestamp; - - if (diff>(int64_t)arguments.wrap_at/2) { - diff -= arguments.wrap_at; - } else if (diff<(-(int64_t)arguments.wrap_at)/2){ - diff += arguments.wrap_at; - } - - debugOutput(DEBUG_LEVEL_NORMAL, "Simulating cycle %d @ time=%011llu, diff=%lld\n",cycle,time,diff); - - if(diff>0) { - ffado_timestamp_t ts_head_tmp, ts_tail_tmp; - uint64_t ts_head, ts_tail; - signed int fc_head, fc_tail; - - // write one packet - t->writeFrames(arguments.frames_per_packet, (char *)&dummyframe_in, timestamp); - - // read the buffer head timestamp - t->getBufferHeadTimestamp(&ts_head_tmp, &fc_head); - t->getBufferTailTimestamp(&ts_tail_tmp, &fc_tail); - ts_head=(uint64_t)ts_head_tmp; - ts_tail=(uint64_t)ts_tail_tmp; - debugOutput(DEBUG_LEVEL_NORMAL, - " TS after write: HEAD: %011llu, FC=%04u\n", - ts_head,fc_head); - debugOutput(DEBUG_LEVEL_NORMAL, - " TAIL: %011llu, FC=%04u\n", - ts_tail,fc_tail); - - // read one packet - t->readFrames(arguments.frames_per_packet, (char *)&dummyframe_out); - - // read the buffer head timestamp - t->getBufferHeadTimestamp(&ts_head_tmp, &fc_head); - t->getBufferTailTimestamp(&ts_tail_tmp, &fc_tail); - ts_head=(uint64_t)ts_head_tmp; - ts_tail=(uint64_t)ts_tail_tmp; - debugOutput(DEBUG_LEVEL_NORMAL, - " TS after write: HEAD: %011llu, FC=%04u\n", - ts_head,fc_head); - debugOutput(DEBUG_LEVEL_NORMAL, - " TAIL: %011llu, FC=%04u\n", - ts_tail,fc_tail); - - // check - bool pass=true; - for (unsigned int i=0;i= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - } - - // simulate the cycle timer clock in ticks - time += 3072; - if (time >= arguments.wrap_at) { - time -= arguments.wrap_at; - } - - // allow for the messagebuffer thread to catch up - SleepRelativeUsec(200); - - if(!run) break; - } - } - - // second run, now do block processing - debugOutput(DEBUG_LEVEL_NORMAL, "Start block read test...\n"); - { - unsigned int blocksize=32; - int dummyframe_out_block[arguments.events_per_frame*arguments.frames_per_packet*blocksize]; - int dummyframe_in[arguments.events_per_frame*arguments.frames_per_packet]; - - for (unsigned int i=0;i= arguments.wrap_at) { - // here we need a modulo because start_at_cycle can be large - timestamp %= arguments.wrap_at; - } - t->setBufferTailTimestamp(timestamp); - - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - - for(unsigned int cycle=arguments.start_at_cycle; - cycle < arguments.start_at_cycle+arguments.total_cycles; - cycle++) { - - // simulate the rate adaptation - int64_t diff=(time%arguments.wrap_at)-timestamp; - - if (diff>(int64_t)arguments.wrap_at/2) { - diff -= arguments.wrap_at; - } else if (diff<(-(int64_t)arguments.wrap_at)/2){ - diff += arguments.wrap_at; - } - - debugOutput(DEBUG_LEVEL_NORMAL, "Simulating cycle %d @ time=%011llu, diff=%lld\n",cycle,time,diff); - - if(diff>0) { - ffado_timestamp_t ts_head_tmp, ts_tail_tmp; - uint64_t ts_head, ts_tail; - signed int fc_head, fc_tail; - - // write one packet - t->writeFrames(arguments.frames_per_packet, (char *)&dummyframe_in, timestamp); - - // read the buffer head timestamp - t->getBufferHeadTimestamp(&ts_head_tmp, &fc_head); - t->getBufferTailTimestamp(&ts_tail_tmp, &fc_tail); - ts_head=(uint64_t)ts_head_tmp; - ts_tail=(uint64_t)ts_tail_tmp; - debugOutput(DEBUG_LEVEL_NORMAL, - " TS after write: HEAD: %011llu, FC=%04u\n", - ts_head,fc_head); - debugOutput(DEBUG_LEVEL_NORMAL, - " TAIL: %011llu, FC=%04u\n", - ts_tail,fc_tail); - - if (fc_head > (signed int)blocksize) { - debugOutput(DEBUG_LEVEL_NORMAL,"Reading one block (%u frames)\n",blocksize); - - // read one block - t->readFrames(blocksize, (char *)&dummyframe_out_block); - - // read the buffer head timestamp - t->getBufferHeadTimestamp(&ts_head_tmp, &fc_head); - t->getBufferTailTimestamp(&ts_tail_tmp, &fc_tail); - ts_head=(uint64_t)ts_head_tmp; - ts_tail=(uint64_t)ts_tail_tmp; - debugOutput(DEBUG_LEVEL_NORMAL, - " TS after read: HEAD: %011llu, FC=%04u\n", - ts_head,fc_head); - debugOutput(DEBUG_LEVEL_NORMAL, - " TAIL: %011llu, FC=%04u\n", - ts_tail,fc_tail); - } - - // update the timestamp - timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); - if (timestamp >= arguments.wrap_at) { - timestamp -= arguments.wrap_at; - } - } - - // simulate the cycle timer clock in ticks - time += 3072; - if (time >= arguments.wrap_at) { - time -= arguments.wrap_at; - } - - // allow for the messagebuffer thread to catch up - SleepRelativeUsec(200); - - if(!run) break; - } - } - - delete t; - delete c; - - return EXIT_SUCCESS; -} - - Index: /anches/libffado-2.0/tests/test-volume.cpp =================================================================== --- /branches/libffado-2.0/tests/test-volume.cpp (revision 1124) +++ (revision ) @@ -1,149 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "libavc/audiosubunit/avc_function_block.h" -#include "libutil/serialize.h" -#include "libutil/cmd_serialize.h" - -#include "libieee1394/ieee1394service.h" - -const bool bVerbose = false; - -using namespace AVC; -using namespace Util; -using namespace Util::Cmd; - -short int -getVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id, - FunctionBlockCmd::EControlAttribute control_attrib ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Feature, - ffb_id, - control_attrib ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Status ); - fbCmd.m_pFBFeature->m_audioChannelNumber = 0; - fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; - fbCmd.m_pFBFeature->m_pVolume->m_volume = 0; - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE ); - } - - if ( !fbCmd.fire() ) { - printf( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return fbCmd.m_pFBFeature->m_pVolume->m_volume; -} - -bool -setVolume( Ieee1394Service& ieee1394service, int node_id, int ffb_id, int vol ) -{ - FunctionBlockCmd fbCmd( ieee1394service, - FunctionBlockCmd::eFBT_Feature, - ffb_id, - FunctionBlockCmd::eCA_Current ); - fbCmd.setNodeId( node_id ); - fbCmd.setSubunitId( 0x00 ); - fbCmd.setCommandType( AVCCommand::eCT_Control ); - fbCmd.m_pFBFeature->m_audioChannelNumber = 0; - fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; - fbCmd.m_pFBFeature->m_pVolume->m_volume = vol; - - fbCmd.setVerbose( bVerbose ); - if (bVerbose) { - ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERBOSE ); - } - - bool bStatus = fbCmd.fire(); - if ( !bStatus ) { - printf( "cmd failed\n" ); - } - - if ( bVerbose ) { - CoutSerializer se; - fbCmd.serialize( se ); - } - - return bStatus; -} - -bool -doApp( Ieee1394Service& ieee1394service, int node_id, int fb_id, int vol ) -{ - short int maxVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Maximum ); - short int minVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Minimum ); - short int curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current ); - printf( "max volume value = %d\n", maxVolume ); - printf( "min volume value = %d\n", minVolume ); - printf( "old volume value = %d\n", curVolume); - - setVolume( ieee1394service, node_id, fb_id, vol ); - - curVolume = getVolume( ieee1394service, node_id, fb_id, FunctionBlockCmd::eCA_Current ); - printf( "new volume value = %d\n", curVolume ); - - return true; -} - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - - if (argc < 3) { - printf("usage: NODE_ID FB_ID VOL\n"); - exit(0); - } - - int errno = 0; - char* tail; - int node_id = strtol( argv[1], &tail, 0 ); - int fb_id = strtol( argv[2], &tail, 0 ); - int vol = strtol( argv[3], &tail, 0 ); - - if (errno) { - perror("argument parsing failed:"); - return -1; - } - Ieee1394Service ieee1394service; - if ( !ieee1394service.initialize( 0 ) ) { - fprintf( stderr, "could not set port on ieee1394service\n" ); - return -1; - } - - doApp( ieee1394service, node_id, fb_id, vol ); - - return 0; -} Index: /anches/libffado-2.0/tests/test-ieee1394service.cpp =================================================================== --- /branches/libffado-2.0/tests/test-ieee1394service.cpp (revision 1135) +++ (revision ) @@ -1,423 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include - -#include -#include "src/debugmodule/debugmodule.h" - -#include "libutil/ByteSwap.h" - -#include "src/libieee1394/cycletimer.h" -#include "src/libieee1394/configrom.h" -#include "src/libieee1394/ieee1394service.h" -#include "src/libieee1394/ARMHandler.h" - -#include "src/libutil/Thread.h" -#include "src/libutil/Functors.h" -#include "src/libutil/PosixThread.h" -#include -#include "libutil/Time.h" - - -#define NB_THREADS 1 -#define THREAD_RT true -#define THREAD_PRIO 51 -#define THREAD_SLEEP_US 50000 - -#define DISP_CYCLE_SLEEP_SECS 2 - -using namespace Util; - -DECLARE_GLOBAL_DEBUG_MODULE; - -#define DIFF_CONSIDERED_LARGE (TICKS_PER_CYCLE/2) -int PORT_TO_USE = 0; -int VERBOSE_LEVEL = 4; - -int max_diff=-99999; -int min_diff= 99999; - -int run=1; -static void sighandler (int sig) -{ - run = 0; -} - -class MyFunctor : public Functor -{ -public: - MyFunctor() {} - virtual ~MyFunctor() {} - - void operator() () { - printf("hello from the functor (%p)\n", this); - }; -}; - -class CtrThread : public Util::RunnableInterface -{ - public: - CtrThread(Ieee1394Service *s) - : m_service(s) - {}; - virtual ~CtrThread() {}; - virtual bool Init() - { - debugOutput(DEBUG_LEVEL_NORMAL, "(%p) Init\n", this); - ctr = 0; - ctr_dll = 0; - - ctr_prev = 0; - ctr_dll_prev = 0; - nb_checks = 0; - summed_diff = 0; - avg_diff = 0; - m_reset_avg = 1; - m_handle = raw1394_new_handle_on_port( PORT_TO_USE ); - if ( !m_handle ) { - if ( !errno ) { - debugFatal("libraw1394 not compatible\n"); - } else { - debugFatal("Ieee1394Service::initialize: Could not get 1394 handle: %s\n", - strerror(errno) ); - debugFatal("Is ieee1394 and raw1394 driver loaded?\n"); - } - return false; - } - return true; - } - virtual bool Execute(); - - Ieee1394Service *m_service; - raw1394handle_t m_handle; - uint64_t ctr; - uint64_t ctr_dll; - - uint64_t ctr_prev; - uint64_t ctr_dll_prev; - - uint64_t nb_checks; - int64_t summed_diff; - double avg_diff; - int m_reset_avg; -}; - -bool CtrThread::Execute() { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p) Execute\n", this); - - SleepRelativeUsec(THREAD_SLEEP_US); - - uint32_t cycle_timer; - uint64_t local_time; - uint32_t cycle_timer2; - uint64_t local_time2; - uint64_t ticks1, ticks2; - int err; - - do { - // read the CTR 'raw' from a handle - // and read it from the 1394 service, which uses a DLL - err = raw1394_read_cycle_timer(m_handle, &cycle_timer2, &local_time2); - err = raw1394_read_cycle_timer(m_handle, &cycle_timer, &local_time); - - ticks1 = CYCLE_TIMER_TO_TICKS(cycle_timer); - ticks2 = CYCLE_TIMER_TO_TICKS(cycle_timer2); - } while (diffTicks(ticks1, ticks2) < 0); - - ctr_prev = ctr; - ctr_dll_prev = ctr_dll; - - ctr = CYCLE_TIMER_TO_TICKS( cycle_timer ); - ctr_dll = m_service->getCycleTimerTicks(local_time); - - if(err) { - debugError("(%p) CTR read error\n", this); - } - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) Cycle timer: %011llu (%03us %04ucy %04uticks)\n", - this, ctr, - (unsigned int)TICKS_TO_SECS( ctr ), - (unsigned int)TICKS_TO_CYCLES( ctr ), - (unsigned int)TICKS_TO_OFFSET( ctr ) ); - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) from DLL: %011llu (%03us %04ucy %04uticks)\n", - this, ctr_dll, - (unsigned int)TICKS_TO_SECS( ctr_dll ), - (unsigned int)TICKS_TO_CYCLES( ctr_dll ), - (unsigned int)TICKS_TO_OFFSET( ctr_dll ) ); - int64_t diff = diffTicks(ctr, ctr_dll); - uint64_t abs_diff; - // for jitter plots - // debugOutput(DEBUG_LEVEL_NORMAL, "9876543210: %lld\n", diff); - - if(m_reset_avg) { - m_reset_avg = 0; - summed_diff = 0; - nb_checks = 0; - } - - // not 100% thread safe, but will do - if (diff > max_diff) max_diff = diff; - if (diff < min_diff) min_diff = diff; - summed_diff += diff; - nb_checks++; - avg_diff = ((double)summed_diff)/((double)nb_checks); - - if (diff < 0) { - abs_diff = -diff; - } else { - abs_diff = diff; - } - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) diff: %s%011llu (%03us %04ucy %04uticks)\n", this, - ((int64_t)abs_diff==diff?" ":"-"), abs_diff, (unsigned int)TICKS_TO_SECS( abs_diff ), - (unsigned int)TICKS_TO_CYCLES( abs_diff ), (unsigned int)TICKS_TO_OFFSET( abs_diff ) ); - if (abs_diff > DIFF_CONSIDERED_LARGE) { - debugWarning("(%p) Alert, large diff: %lld\n", this, diff); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) Cycle timer: %011llu (%03us %04ucy %04uticks)\n", - this, ctr, - (unsigned int)TICKS_TO_SECS( ctr ), - (unsigned int)TICKS_TO_CYCLES( ctr ), - (unsigned int)TICKS_TO_OFFSET( ctr ) ); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) from DLL: %011llu (%03us %04ucy %04uticks)\n", - this, ctr_dll, - (unsigned int)TICKS_TO_SECS( ctr_dll ), - (unsigned int)TICKS_TO_CYCLES( ctr_dll ), - (unsigned int)TICKS_TO_OFFSET( ctr_dll ) ); - } - - diff = diffTicks(ctr, ctr_prev); - if (diff < 0) { - debugWarning("(%p) Alert, non-monotonic ctr (direct): %llu - %llu = %lld\n", - this, ctr, ctr_prev, diff); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) Cycle timer now : %011llu (%03us %04ucy %04uticks)\n", - this, ctr, - (unsigned int)TICKS_TO_SECS( ctr ), - (unsigned int)TICKS_TO_CYCLES( ctr ), - (unsigned int)TICKS_TO_OFFSET( ctr ) ); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) Cycle timer prev: %011llu (%03us %04ucy %04uticks)\n", - this, ctr_prev, - (unsigned int)TICKS_TO_SECS( ctr_prev ), - (unsigned int)TICKS_TO_CYCLES( ctr_prev ), - (unsigned int)TICKS_TO_OFFSET( ctr_prev ) ); - } - diff = diffTicks(ctr_dll, ctr_dll_prev); - if (diff < 0) { - debugWarning("(%p) Alert, non-monotonic ctr (dll): %llu - %llu = %lld\n", - this, ctr_dll, ctr_dll_prev, diff); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) Cycle timer now : %011llu (%03us %04ucy %04uticks)\n", - this, ctr_dll, - (unsigned int)TICKS_TO_SECS( ctr_dll ), - (unsigned int)TICKS_TO_CYCLES( ctr_dll ), - (unsigned int)TICKS_TO_OFFSET( ctr_dll ) ); - debugOutput ( DEBUG_LEVEL_NORMAL, - "(%p) Cycle timer prev: %011llu (%03us %04ucy %04uticks)\n", - this, ctr_dll_prev, - (unsigned int)TICKS_TO_SECS( ctr_dll_prev ), - (unsigned int)TICKS_TO_CYCLES( ctr_dll_prev ), - (unsigned int)TICKS_TO_OFFSET( ctr_dll_prev ) ); - } - - // check some calculations - uint32_t tmp_orig = m_service->getCycleTimer(); - uint32_t tmp_ticks = CYCLE_TIMER_TO_TICKS(tmp_orig); - uint32_t tmp_ctr = TICKS_TO_CYCLE_TIMER(tmp_ticks); - - if (tmp_orig != tmp_ctr) { - debugError("CTR => TICKS => CTR failed\n"); - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) orig CTR : %08X (%03us %04ucy %04uticks)\n", - this, (uint32_t)tmp_orig, - (unsigned int)CYCLE_TIMER_GET_SECS( tmp_orig ), - (unsigned int)CYCLE_TIMER_GET_CYCLES( tmp_orig ), - (unsigned int)CYCLE_TIMER_GET_OFFSET( tmp_orig ) ); - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) TICKS: %011llu (%03us %04ucy %04uticks)\n", - this, tmp_ticks, - (unsigned int)TICKS_TO_SECS( tmp_ticks ), - (unsigned int)TICKS_TO_CYCLES( tmp_ticks ), - (unsigned int)TICKS_TO_OFFSET( tmp_ticks ) ); - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) new CTR : %08X (%03us %04ucy %04uticks)\n", - this, (uint32_t)tmp_ctr, - (unsigned int)CYCLE_TIMER_GET_SECS( tmp_ctr ), - (unsigned int)CYCLE_TIMER_GET_CYCLES( tmp_ctr ), - (unsigned int)CYCLE_TIMER_GET_OFFSET( tmp_ctr ) ); - } - - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "(%p) wait...\n", this); - return true; -} - -int main(int argc, char *argv[]) -{ - int i=0; - signal (SIGINT, sighandler); - signal (SIGPIPE, sighandler); - - static struct option long_opts[] = { { "port", 1, 0, 'p' }, { "verbose", 1, 0, 'v' }, { "help", 0, 0, 'h' }, { 0, 0, 0, 0 } }; - int optindex = 0; - while(1) { - int c = getopt_long( argc, argv, "p:h", long_opts, &optindex ); - if(c==-1) - break; - switch(c) { - case 'p': - PORT_TO_USE = atoi( optarg ); - break; - case 'v': - VERBOSE_LEVEL = atoi( optarg ); - break; - case 'h': - printf( "USAGE:\n\ - Currently two options are understood:\n\ - --port or -p selects the firewire-port to use, default is 0\n\ - --verbose or -v selects the verbose level, default is 4\n\ - --help or -h shows this help and exits.\n\ -" ); - return 0; - break; - } - } - - printf("FFADO Ieee1394Service test application\n"); - printf(" Using port %d\n", PORT_TO_USE); - printf(" Verbose level %d\n", VERBOSE_LEVEL); - - setDebugLevel(VERBOSE_LEVEL); - - Ieee1394Service *m_service=NULL; - - m_service = new Ieee1394Service(); - m_service->setVerboseLevel(VERBOSE_LEVEL); - if(!m_service->initialize(PORT_TO_USE)) { - printf("Could not initialize 1394 service\n"); - delete m_service; - exit(-1); - } - m_service->setThreadParameters(true, 1); - - MyFunctor *test_busreset=new MyFunctor(); - - printf(" adding (%p) as busreset handler\n", test_busreset); - - m_service->addBusResetHandler(test_busreset); - - nodeaddr_t addr = m_service->findFreeARMBlock(0x0000FFFFE0000000ULL, 4, 4 ); - - ARMHandler *test_arm=new ARMHandler(addr, - 4, - RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, - RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, - 0); - - printf(" adding (%p) as arm handler\n", test_arm); - - if (!m_service->registerARMHandler(test_arm)) { - printf(" failed\n"); - } - - addr = m_service->findFreeARMBlock(0x0000FFFFE0000000ULL, 4, 4 ); - - ARMHandler *test_arm2=new ARMHandler(addr, - 4, - RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, - RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, - 0); - - printf(" adding (%p) as arm handler\n", test_arm2); - - if (!m_service->registerARMHandler(test_arm2)) { - printf(" failed\n"); - } - - CtrThread *thread_runners[NB_THREADS]; - Thread* threads[NB_THREADS]; - for (i=0; i < NB_THREADS; i++) { - thread_runners[i] = new CtrThread(m_service); - if (thread_runners[i] == NULL) { - debugError("could not create thread runner %d\n", i); - exit(-1); - } - threads[i] = new PosixThread(thread_runners[i], THREAD_RT, THREAD_PRIO, PTHREAD_CANCEL_DEFERRED); - if (threads[i] == NULL) { - debugError("could not create thread %d\n", i); - exit(-1); - } - } - - for (i=0; i < NB_THREADS; i++) { - threads[i]->Start(); - } - - int cnt=0; - while(run) { - cnt++; - debugOutput(DEBUG_LEVEL_NORMAL, "%08d: (max: %6d, min: %6d)\n", cnt, max_diff, min_diff); - m_service->show(); - max_diff = -999999; - min_diff = 999999; - - for (i=0; i < NB_THREADS; i++) { - debugOutput(DEBUG_LEVEL_NORMAL, "%2d: avg: %6f\n", i, thread_runners[i]->avg_diff); - thread_runners[i]->m_reset_avg = 1; - } - - - sleep(DISP_CYCLE_SLEEP_SECS); - } - - for (i=0; i < NB_THREADS; i++) { - threads[i]->Stop(); - } - - for (i=0; i < NB_THREADS; i++) { - delete threads[i]; - delete thread_runners[i]; - } - - delete m_service; - delete test_busreset; - delete test_arm; - delete test_arm2; - - printf("Bye...\n"); - - return EXIT_SUCCESS; -} Index: /anches/libffado-2.0/tests/test-extplugcmd.cpp =================================================================== --- /branches/libffado-2.0/tests/test-extplugcmd.cpp (revision 1146) +++ (revision ) @@ -1,223 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "libavc/avc_extended_plug_info.h" -#include "libavc/avc_plug_info.h" -#include "libavc/avc_serialize.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" - -#include - -using namespace std; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-extplugcmd 0.2"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-extplugcmd -- tests some extended plug info commands on a BeBoB device"; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - { 0 } -}; - -struct arguments -{ - arguments() - : verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[1]; - bool verbose; - bool test; - int port; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - errno = 0; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 1) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 1) { - // Not enough arguments. - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -//////////////////////////////////////// -// Application -//////////////////////////////////////// - -bool -doPlugType( Ieee1394Service& ieee1394service, int node_id ) -{ - ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service ); - UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); - extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, - PlugAddress::ePAM_Unit, - unitPlugAddress ) ); - extPlugInfoCmd.setNodeId( node_id ); - extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); - extPlugInfoCmd.setVerbose( arguments.verbose ); - ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugType ); - extendedPlugInfoInfoType.initialize(); - extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); - - if ( extPlugInfoCmd.fire() ) { - CoutSerializer se; - extPlugInfoCmd.serialize( se ); - } - - ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); - if ( infoType - && infoType->m_plugType ) - { - plug_type_t plugType = infoType->m_plugType->m_plugType; - - printf( "iso input plug %d is of type %d (%s)\n", - 0, - plugType, - extendedPlugInfoPlugTypeToString( plugType ) ); - } else { - fprintf( stderr, "Not plug name specific data found\n" ); - return false; - } - - return true; -} - - -bool -doPlugName( Ieee1394Service& ieee1394service, int node_id ) -{ - ExtendedPlugInfoCmd extPlugInfoCmd( ieee1394service ); - UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR, 0 ); - extPlugInfoCmd.setPlugAddress( PlugAddress( PlugAddress::ePD_Input, - PlugAddress::ePAM_Unit, - unitPlugAddress ) ); - extPlugInfoCmd.setNodeId( node_id ); - extPlugInfoCmd.setCommandType( AVCCommand::eCT_Status ); - extPlugInfoCmd.setVerbose( arguments.verbose ); - ExtendedPlugInfoInfoType extendedPlugInfoInfoType( ExtendedPlugInfoInfoType::eIT_PlugName ); - extendedPlugInfoInfoType.initialize(); - extPlugInfoCmd.setInfoType( extendedPlugInfoInfoType ); - - if ( extPlugInfoCmd.fire() ) { - CoutSerializer se; - extPlugInfoCmd.serialize( se ); - } - - ExtendedPlugInfoInfoType* infoType = extPlugInfoCmd.getInfoType(); - if ( infoType - && infoType->m_plugName ) - { - printf( "iso input plug %d has name '%s'\n", - 0, - infoType->m_plugName->m_name.c_str() ); - } else { - fprintf( stderr, "Not plug name specific data found\n" ); - return false; - } - - return true; -} - -bool -doApp(Ieee1394Service& ieee1394service, int node_id ) -{ - bool success; - - success = doPlugType( ieee1394service, node_id ); - success &= doPlugName( ieee1394service, node_id ); - - return success; -} - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int node_id = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - Ieee1394Service ieee1394service; - if ( !ieee1394service.initialize( arguments.port ) ) { - fprintf( stderr, "could not set port on ieee1394service\n" ); - return -1; - } - - doApp( ieee1394service, node_id ); - - return 0; -} Index: /anches/libffado-2.0/tests/test-echo.cpp =================================================================== --- /branches/libffado-2.0/tests/test-echo.cpp (revision 864) +++ (revision ) @@ -1,210 +1,0 @@ -/* - * Copyright (C) 2005-2008 by Pieter Palmers - * Copyright (C) 2005-2008 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include -#include "libutil/Time.h" - -#include -#include -#include - -using namespace std; - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "test-echo 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "test-echo -- test program for the ECHO AUDIOFIRE devices"; -static char args_doc[] = "NODE_ID"; -static struct argp_option options[] = { - {"verbose", 'v', 0, 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - { 0 } -}; - -struct arguments -{ - arguments() - : verbose( false ) - , test( false ) - , port( 0 ) - { - args[0] = 0; - } - - char* args[1]; - bool verbose; - bool test; - int port; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - switch (key) { - case 'v': - arguments->verbose = true; - break; - case 't': - arguments->test = true; - break; - case 'p': - errno = 0; - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 1) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 1) { - // Not enough arguments. - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - -/////////////////////////// -// main -////////////////////////// -int -main(int argc, char **argv) -{ - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int iNodeId = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - raw1394handle_t pHandle = raw1394_new_handle_on_port( arguments.port ); - if ( !pHandle ) { - if ( !errno ) { - cerr << "libraw1394 not compatible" << endl; - } else { - perror( "Could not get 1394 handle" ); - cerr << "Is ieee1394 and raw1394 driver loaded?" << endl; - } - return -1; - } - quadlet_t cmd[6]; - unsigned int response_len; - -// cerr << "Opening descriptor" << endl; -// 0h 05m 21.760442s - GetDescriptorOpen: cmd[0]= < 0x00 0x60 0x08 0x80 0x01 0xFF> -// 0h 05m 21.760687s - GetDescriptorOpen: resp[0]= < 0x09 0x60 0x08 0x80 0x01 0xFF > ACCEPTED - - -// cmd[0] = 0x00600880; -// cmd[1] = 0x01FF0000; -// avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); -// SleepRelativeUsec(100000); -// -// cerr << "Reading descriptor" << endl; -// // 0h 05m 21.760700s - GetDescriptorRead: cmd[0]= < 0x00 0x60 0x09 0x80 0xFF 0xFF 0x00 0x00 0x00 0x00> -// // 0h 05m 21.761123s - GetDescriptorRead: resp[0]= < 0x09 0x60 0x09 0x80 0x11 0xFF 0x01 0xF6 0x00 0x00 0x03 0x9E -// cmd[0] = 0x00600980; -// cmd[1] = 0xFFFF0000; -// cmd[2] = 0x00000000; -// cmd[2] = 0x00000000; -// -// avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 3, &response_len, 10); -// SleepRelativeUsec(100000); -// -// cerr << "Closing descriptor" << endl; -// cmd[0] = 0x00600880; -// cmd[1] = 0x00FF0000; -// avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); -// SleepRelativeUsec(100000); - - cerr << "getting signal source" << endl; -// 0h 05m 21.762917s - at line 2283, fMaxAudioOutputChannels=2, fMaxAudioInputChannels=0 -// 0h 05m 21.762919s - GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0xFF 0x00> -// 0h 05m 21.763149s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x60 0x60 0x00 0xFF 0x00 > IMPLEMENTED -// 0h 05m 21.763167s - Isoch out 0 gets its signal from sub/unit 0x60 Source Plug 0 -// 0h 05m 21.763170s - GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0xFF 0x80> -// 0h 05m 21.763376s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x00 0x60 0x01 0xFF 0x80 > IMPLEMENTED -// 0h 05m 21.763394s - Isoch out 128 gets its signal from sub/unit 0x60 Source Plug 1 -// 0h 05m 21.763397s - GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0xFF 0x81> -// 0h 05m 21.763637s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x00 0x60 0x02 0xFF 0x81 > IMPLEMENTED -// 0h 05m 21.763654s - Isoch out 129 gets its signal from sub/unit 0x60 Source Plug 2 - -// 0h 05m 21.764895s - Starting to look at subunit 1. fNumberOfSubUnits = 2 -// 0h 05m 21.764897s - Subunit 1 GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0x60 0x00> -// 0h 05m 21.765129s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x20 0xFF 0x00 0x60 0x00 > IMPLEMENTED -// 0h 05m 21.765140s - Subunit type12, addr:0x60 dest 0 gets its signal from sub/unit 0xff Source Plug 0 -// 0h 05m 21.765142s - subunit 96 dest plug 0 is routed -// 0h 05m 21.765143s - Subunit 1 GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0x60 0x01> -// 0h 05m 21.765364s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x00 0xFF 0x80 0x60 0x01 > IMPLEMENTED -// 0h 05m 21.765382s - Subunit type12, addr:0x60 dest 1 gets its signal from sub/unit 0xff Source Plug 128 -// 0h 05m 21.765385s - Plug being changed from 0x80 to 1 for internal bookeeping. -// 0h 05m 21.765389s - Subunit 1 GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0x60 0x02> -// 0h 05m 21.765632s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x00 0xFF 0x81 0x60 0x02 > IMPLEMENTED -// 0h 05m 21.765651s - Subunit type12, addr:0x60 dest 2 gets its signal from sub/unit 0xff Source Plug 129 -// 0h 05m 21.765653s - Plug being changed from 0x81 to 2 for internal bookeeping. -// 0h 05m 21.765657s - Subunit 1 GetSignalSource: cmd[0]= < 0x01 0xFF 0x1A 0xFF 0xFF 0xFE 0x60 0x03> -// 0h 05m 21.765874s - GetSignalSource: resp[0]= < 0x0c 0xFF 0x1A 0x00 0x60 0x03 0x60 0x03 > IMPLEMENTED -// 0h 05m 21.765892s - Subunit type12, addr:0x60 dest 3 gets its signal from sub/unit 0x60 Source Plug 3 - - cmd[0] = 0x01FF1AFF; - cmd[1] = 0xFFFE6000; - avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); -// SleepRelativeUsec(100000); - - cmd[0] = 0x01FF1AFF; - cmd[1] = 0xFFFEFF00; - avc1394_transaction_block2(pHandle, 0xffc0 | iNodeId, cmd, 2, &response_len, 10); - SleepRelativeUsec(100000); - - - - raw1394_destroy_handle( pHandle ); - return 0; -} Index: /branches/libffado-2.0/SConstruct =================================================================== --- /branches/libffado-2.0/SConstruct (revision 1180) +++ /branches/libffado-2.0/SConstruct (revision 1190) @@ -25,5 +25,5 @@ FFADO_API_VERSION="8" -FFADO_VERSION="1.999.27" +FFADO_VERSION="1.999.28" import os @@ -65,8 +65,4 @@ BoolOption( "ENABLE_FIREWORKS", "Enable/Disable the ECHO Audio FireWorks AV/C part.", True ), BoolOption( "ENABLE_MOTU", "Enable/Disable the MOTU part.", True ), - BoolOption( "ENABLE_DICE", "Enable/Disable the DICE part.", False ), - BoolOption( "ENABLE_METRIC_HALO", "Enable/Disable the Metric Halo part.", False ), - BoolOption( "ENABLE_RME", "Enable/Disable the RME part.", False ), - BoolOption( "ENABLE_BOUNCE", "Enable/Disable the BOUNCE part.", False ), BoolOption( "ENABLE_GENERICAVC", """\ Enable/Disable the the generic avc part (mainly used by apple). @@ -326,10 +322,6 @@ env['ENABLE_FIREWORKS'] = True env['ENABLE_MOTU'] = True - env['ENABLE_DICE'] = True - env['ENABLE_METRIC_HALO'] = True - env['ENABLE_RME'] = True - env['ENABLE_BOUNCE'] = True - -if env['ENABLE_BEBOB'] or env['ENABLE_DICE'] or env['ENABLE_BOUNCE'] or env['ENABLE_FIREWORKS']: + +if env['ENABLE_BEBOB'] or env['ENABLE_FIREWORKS']: env['ENABLE_GENERICAVC'] = True @@ -523,7 +515,4 @@ env.SConscript( dirs=subdirs, exports="env" ) -if 'debian' in COMMAND_LINE_TARGETS: - env.SConscript("deb/SConscript", exports="env") - # By default only src is built but all is cleaned if not env.GetOption('clean'):