Index: trunk/libffado/src/libieee1394/CycleTimerHelper.cpp =================================================================== --- trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 864) +++ trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 866) @@ -165,5 +165,5 @@ CycleTimerHelper::Execute() { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Execute %p...\n", this); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "Execute %p...\n", this); if (!m_first_run) { // wait for the next update period @@ -182,6 +182,6 @@ return false; } - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " read : CTR: %11lu, local: %17llu\n", - cycle_timer, local_time); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " read : CTR: %11lu, local: %17llu\n", + cycle_timer, local_time); if (m_first_run) { @@ -226,14 +226,13 @@ m_next_time_usecs = local_time + m_usecs_per_update; - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " usecs: current: %f next: %f usecs_late=%f\n", - m_current_time_usecs, m_next_time_usecs, usecs_late); - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " ticks: current: %f next: %f diff=%f\n", - m_current_time_ticks, m_next_time_ticks, diff_ticks); - - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, " state: local: %11llu, dll_e2: %f, rate: %f\n", - local_time, m_dll_e2, getRate()); - } - - // FIXME: priority inversion! + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " usecs: current: %f next: %f usecs_late=%f\n", + m_current_time_usecs, m_next_time_usecs, usecs_late); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " ticks: current: %f next: %f diff=%f\n", + m_current_time_ticks, m_next_time_ticks, diff_ticks); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " state: local: %11llu, dll_e2: %f, rate: %f\n", + local_time, m_dll_e2, getRate()); + } + + // FIXME: priority inversion possible, run this at higher prio than client threads ENTER_CRITICAL_SECTION; m_current_vars.ticks = (uint64_t)(m_current_time_ticks);// + m_average_offset_ticks); @@ -270,12 +269,12 @@ if (y_step_in_ticks_int > 0) { retval = addTicks(offset_in_ticks_int, y_step_in_ticks_int); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int > 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", - y_step_in_ticks_int, time_diff, my_vars.rate, retval); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int > 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", + y_step_in_ticks_int, time_diff, my_vars.rate, retval); } else { retval = substractTicks(offset_in_ticks_int, -y_step_in_ticks_int); // this can happen if the update thread was woken up earlier than it should have been - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int <= 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", - y_step_in_ticks_int, time_diff, my_vars.rate, retval); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "y_step_in_ticks_int <= 0: %lld, time_diff: %f, rate: %f, retval: %lu\n", + y_step_in_ticks_int, time_diff, my_vars.rate, retval); } Index: trunk/libffado/src/libieee1394/cycletimer.h =================================================================== --- trunk/libffado/src/libieee1394/cycletimer.h (revision 864) +++ trunk/libffado/src/libieee1394/cycletimer.h (revision 866) @@ -305,6 +305,6 @@ uint64_t timestamp; - debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%04llX CY=%u CTR=%08llX\n", - syt_timestamp, rcv_cycle, ctr_now); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "SYT=%04llX CY=%u CTR=%08llX\n", + syt_timestamp, rcv_cycle, ctr_now); // reconstruct the full cycle @@ -345,7 +345,7 @@ timestamp = new_cycles * TICKS_PER_CYCLE; } else { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, - "Detected wraparound: %d + %d = %d\n", - rcv_cycle,delta_cycles,new_cycles); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "Detected wraparound: %d + %d = %d\n", + rcv_cycle, delta_cycles, new_cycles); new_cycles-=8000; // wrap around @@ -391,6 +391,6 @@ uint64_t timestamp; - debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"SYT=%08llX CY=%04X CTR=%08llX\n", - syt_timestamp,xmt_cycle,ctr_now); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "SYT=%08llX CY=%04X CTR=%08llX\n", + syt_timestamp, xmt_cycle, ctr_now); // reconstruct the full cycle @@ -431,7 +431,7 @@ timestamp = new_cycles * TICKS_PER_CYCLE; } else { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, - "Detected wraparound: %d + %d = %d\n", - xmt_cycle,delta_cycles,new_cycles); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "Detected wraparound: %d + %d = %d\n", + xmt_cycle, delta_cycles, new_cycles); new_cycles-=8000; // wrap around Index: trunk/libffado/src/libieee1394/IsoHandlerManager.cpp =================================================================== --- trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 864) +++ trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 866) @@ -154,7 +154,7 @@ // Use a shadow map of the fd's such that the poll call is not in a critical section - uint64_t poll_enter = m_service.getCurrentTimeAsUsecs(); + DEBUG_EXTREME( uint64_t poll_enter = m_service.getCurrentTimeAsUsecs() ); err = poll (m_poll_fds_shadow, m_poll_nfds_shadow, m_poll_timeout); - uint64_t poll_exit = m_service.getCurrentTimeAsUsecs(); + DEBUG_EXTREME( uint64_t poll_exit = m_service.getCurrentTimeAsUsecs() ); if (err == -1) { @@ -168,9 +168,9 @@ int nb_rcv = 0; int nb_xmit = 0; - uint64_t iter_enter = m_service.getCurrentTimeAsUsecs(); + DEBUG_EXTREME( uint64_t iter_enter = m_service.getCurrentTimeAsUsecs() ); for (i = 0; i < m_poll_nfds_shadow; i++) { if(m_poll_fds_shadow[i].revents) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "received events: %08X for (%p)\n", - m_poll_fds_shadow[i].revents, m_IsoHandler_map_shadow[i]); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "received events: %08X for (%p)\n", + m_poll_fds_shadow[i].revents, m_IsoHandler_map_shadow[i]); } if (m_poll_fds_shadow[i].revents & POLLERR) { @@ -195,9 +195,9 @@ } } - uint64_t iter_exit = m_service.getCurrentTimeAsUsecs(); - - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " poll took %6lldus, iterate took %6lldus, iterated (R: %2d, X: %2d) handlers\n", - poll_exit-poll_enter, iter_exit-iter_enter, - nb_rcv, nb_xmit); + DEBUG_EXTREME( uint64_t iter_exit = m_service.getCurrentTimeAsUsecs() ); + + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, " poll took %6lldus, iterate took %6lldus, iterated (R: %2d, X: %2d) handlers\n", + poll_exit-poll_enter, iter_exit-iter_enter, + nb_rcv, nb_xmit); return true; Index: trunk/libffado/src/libieee1394/IsoHandler.cpp =================================================================== --- trunk/libffado/src/libieee1394/IsoHandler.cpp (revision 864) +++ trunk/libffado/src/libieee1394/IsoHandler.cpp (revision 866) @@ -83,6 +83,4 @@ , m_max_packet_size( 1024 ) , m_irq_interval( -1 ) - , m_packetcount( 0 ) - , m_dropped( 0 ) , m_Client( 0 ) , m_poll_timeout( 100 ) @@ -104,6 +102,4 @@ , m_max_packet_size( max_packet_size ) , m_irq_interval( irq ) - , m_packetcount( 0 ) - , m_dropped( 0 ) , m_Client( 0 ) , m_poll_timeout( 100 ) @@ -126,6 +122,4 @@ , m_max_packet_size( max_packet_size ) , m_irq_interval( irq ) - , m_packetcount( 0 ) - , m_dropped( 0 ) , m_Client( 0 ) , m_poll_timeout( 100 ) @@ -174,5 +168,5 @@ IsoHandler::waitForClient() { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "waiting...\n"); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "waiting...\n"); if(m_Client) { bool result; @@ -182,8 +176,8 @@ result = m_Client->waitForConsumePacket(); } - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " returns %d\n", result); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, " returns %d\n", result); return result; } else { - debugOutput(DEBUG_LEVEL_VERBOSE, " no client\n"); + debugOutputExtreme(DEBUG_LEVEL_VERBOSE, " no client\n"); } return false; @@ -193,5 +187,5 @@ IsoHandler::tryWaitForClient() { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "waiting...\n"); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "waiting...\n"); if(m_Client) { bool result; @@ -201,8 +195,8 @@ result = m_Client->canConsumePacket(); } - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " returns %d\n", result); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, " returns %d\n", result); return result; } else { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " no client\n"); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, " no client\n"); } return false; @@ -212,5 +206,5 @@ IsoHandler::Execute() { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "%p: Execute thread...\n", this); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "%p: Execute thread...\n", this); // bypass if not running @@ -224,5 +218,5 @@ // wait for the availability of frames in the client // (blocking for transmit handlers) - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) Waiting for Client activity...\n", this, getTypeString()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) Waiting for Client activity...\n", this, getTypeString()); if (waitForClient()) { #if ISOHANDLER_USE_POLL @@ -277,5 +271,5 @@ bool IsoHandler::iterate() { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) Iterating ISO handler...\n", + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) Iterating ISO handler...\n", this, getTypeString()); if(m_State == E_Running) { @@ -288,6 +282,6 @@ return false; } - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) done interating ISO handler...\n", - this, getTypeString()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) done interating ISO handler...\n", + this, getTypeString()); return true; } else { @@ -427,6 +421,4 @@ m_speed, m_prebuffers); } - debugOutputShort( DEBUG_LEVEL_NORMAL, " Packet count................: %10d (%5d dropped)\n", - this->getPacketCount(), this->getDroppedCount()); } @@ -478,10 +470,7 @@ unsigned int cycle, unsigned int dropped) { -/* debugOutput( DEBUG_LEVEL_VERY_VERBOSE, - "received packet: length=%d, channel=%d, cycle=%d\n", - length, channel, cycle );*/ - m_packetcount++; - m_dropped += dropped; - + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "received packet: length=%d, channel=%d, cycle=%d\n", + length, channel, cycle); if(m_Client) { return m_Client->putPacket(data, length, channel, tag, sy, cycle, dropped); @@ -497,10 +486,7 @@ int cycle, unsigned int dropped) { -/* debugOutput( DEBUG_LEVEL_ULTRA_VERBOSE, - "sending packet: length=%d, cycle=%d\n", - *length, cycle );*/ - m_packetcount++; - m_dropped += dropped; - + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "sending packet: length=%d, cycle=%d\n", + *length, cycle); if(m_Client) { return m_Client->getPacket(data, length, tag, sy, cycle, dropped, m_max_packet_size); Index: trunk/libffado/src/libieee1394/IsoHandler.h =================================================================== --- trunk/libffado/src/libieee1394/IsoHandler.h (revision 864) +++ trunk/libffado/src/libieee1394/IsoHandler.h (revision 866) @@ -113,10 +113,4 @@ int getPacketLatency() { return m_irq_interval;}; - int getPacketCount() {return m_packetcount;}; - void resetPacketCount() {m_packetcount=0;}; - - int getDroppedCount() {return m_dropped;}; - void resetDroppedCount() {m_dropped=0;}; - unsigned int getPreBuffers() {return m_prebuffers;}; void setPreBuffers(unsigned int n) {m_prebuffers=n;}; @@ -141,6 +135,4 @@ int m_irq_interval; - int m_packetcount; - int m_dropped; Streaming::StreamProcessor *m_Client; Index: trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp =================================================================== --- trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (revision 864) +++ trunk/libffado/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (revision 866) @@ -84,5 +84,6 @@ int cycles_until_transmit; - debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "Try for cycle %d\n", cycle ); + debugOutputExtreme( DEBUG_LEVEL_ULTRA_VERBOSE, + "Try for cycle %d\n", cycle ); // check whether the packet buffer has packets for us to send. // the base timestamp is the one of the next sample in the buffer @@ -117,10 +118,10 @@ if (dropped) { - debugOutput ( DEBUG_LEVEL_VERBOSE, - "Gen HDR: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", - cycle, - transmit_at_cycle, cycles_until_transmit, - transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ), - presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) ); + debugOutput( DEBUG_LEVEL_VERBOSE, + "Gen HDR: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", + cycle, + transmit_at_cycle, cycles_until_transmit, + transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), + presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time) ); } // two different options: @@ -138,7 +139,7 @@ if ( cycles_until_presentation <= AMDTP_MIN_CYCLES_BEFORE_PRESENTATION ) { - debugOutput ( DEBUG_LEVEL_VERBOSE, - "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", - fc, cycle, transmit_at_cycle, cycles_until_transmit ); + debugOutput( DEBUG_LEVEL_NORMAL, + "Insufficient frames (P): N=%02d, CY=%04u, TC=%04u, CUT=%04d\n", + fc, cycle, transmit_at_cycle, cycles_until_transmit ); // we are too late return eCRV_XRun; @@ -148,9 +149,7 @@ unsigned int now_cycle = ( unsigned int ) ( TICKS_TO_CYCLES ( m_1394service.getCycleTimerTicks() ) ); - debugOutput ( DEBUG_LEVEL_VERBOSE, - "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d, NOW=%04d\n", - fc, cycle, transmit_at_cycle, cycles_until_transmit, now_cycle ); - debugWarning("Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d, NOW=%04d\n", - fc, cycle, transmit_at_cycle, cycles_until_transmit, now_cycle ); + debugOutputExtreme(DEBUG_LEVEL_VERBOSE, + "Insufficient frames (NP): N=%02d, CY=%04u, TC=%04u, CUT=%04d, NOW=%04d\n", + fc, cycle, transmit_at_cycle, cycles_until_transmit, now_cycle ); // there is still time left to send the packet @@ -195,5 +194,5 @@ { // we are too late - debugOutput(DEBUG_LEVEL_VERBOSE, + debugOutput(DEBUG_LEVEL_NORMAL, "Too late: CY=%04u, TC=%04u, CUT=%04d, TSP=%011llu (%04u)\n", cycle, @@ -224,19 +223,19 @@ else { - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", - cycle, - transmit_at_cycle, cycles_until_transmit, - transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ), - presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) ); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "Too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", + cycle, + transmit_at_cycle, cycles_until_transmit, + transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), + presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); #ifdef DEBUG if ( cycles_until_transmit > AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY + 1 ) { - debugOutput ( DEBUG_LEVEL_VERY_VERBOSE, - "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", - cycle, - transmit_at_cycle, cycles_until_transmit, - transmit_at_time, ( unsigned int ) TICKS_TO_CYCLES ( transmit_at_time ), - presentation_time, ( unsigned int ) TICKS_TO_CYCLES ( presentation_time ) ); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "Way too early: CY=%04u, TC=%04u, CUT=%04d, TST=%011llu (%04u), TSP=%011llu (%04u)\n", + cycle, + transmit_at_cycle, cycles_until_transmit, + transmit_at_time, (unsigned int)TICKS_TO_CYCLES(transmit_at_time), + presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); } #endif @@ -256,6 +255,7 @@ if ( m_data_buffer->readFrames ( m_syt_interval, ( char * ) ( data + 8 ) ) ) { - debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "XMIT DATA (cy %04d): TSP=%011llu (%04u)\n", - cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) ); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "XMIT DATA (cy %04d): TSP=%011llu (%04u)\n", + cycle, m_last_timestamp, (unsigned int)TICKS_TO_CYCLES(m_last_timestamp)); return eCRV_OK; } @@ -271,6 +271,7 @@ { struct iec61883_packet *packet = ( struct iec61883_packet * ) data; - debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "XMIT SILENT (cy %04d): CY=%04u, TSP=%011llu (%04u)\n", - cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) ); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "XMIT SILENT (cy %04d): CY=%04u, TSP=%011llu (%04u)\n", + cycle, m_last_timestamp, (unsigned int)TICKS_TO_CYCLES(m_last_timestamp)); packet->sid = m_local_node_id; @@ -308,6 +309,7 @@ { struct iec61883_packet *packet = ( struct iec61883_packet * ) data; - debugOutput ( DEBUG_LEVEL_ULTRA_VERBOSE, "XMIT EMPTY (cy %04d): CY=%04u, TSP=%011llu (%04u)\n", - cycle, m_last_timestamp, ( unsigned int ) TICKS_TO_CYCLES ( m_last_timestamp ) ); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "XMIT EMPTY (cy %04d): CY=%04u, TSP=%011llu (%04u)\n", + cycle, m_last_timestamp, (unsigned int)TICKS_TO_CYCLES(m_last_timestamp) ); packet->sid = m_local_node_id; @@ -1034,6 +1036,7 @@ { AmdtpPortInfo *pinfo=dynamic_cast(*it); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "idx %u: looking at port %s at position %u\n", - idx, (*it)->getName().c_str(), pinfo->getPosition()); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, + "idx %u: looking at port %s at position %u\n", + idx, (*it)->getName().c_str(), pinfo->getPosition()); if(pinfo->getPosition() == idx) { struct _MBLA_port_cache p; @@ -1049,6 +1052,7 @@ m_audio_ports.push_back(p); - debugOutput(DEBUG_LEVEL_VERBOSE, "Cached port %s at position %u\n", - p.port->getName().c_str(), idx); + debugOutput(DEBUG_LEVEL_VERBOSE, + "Cached port %s at position %u\n", + p.port->getName().c_str(), idx); goto next_index; } @@ -1065,6 +1069,7 @@ { AmdtpPortInfo *pinfo=dynamic_cast(*it); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "idx %u: looking at port %s at position %u, location %u\n", - idx, (*it)->getName().c_str(), pinfo->getPosition(), pinfo->getLocation()); + debugOutput(DEBUG_LEVEL_VERY_VERBOSE, + "idx %u: looking at port %s at position %u, location %u\n", + idx, (*it)->getName().c_str(), pinfo->getPosition(), pinfo->getLocation()); if ((*it)->getPortType() == Port::E_Midi) { struct _MIDI_port_cache p; @@ -1082,6 +1087,7 @@ m_midi_ports.push_back(p); - debugOutput(DEBUG_LEVEL_VERBOSE, "Cached port %s at position %u, location %u\n", - p.port->getName().c_str(), p.position, p.location); + debugOutput(DEBUG_LEVEL_VERBOSE, + "Cached port %s at position %u, location %u\n", + p.port->getName().c_str(), p.position, p.location); } } Index: trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp =================================================================== --- trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp (revision 864) +++ trunk/libffado/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp (revision 866) @@ -161,6 +161,7 @@ #ifdef DEBUG if(isRunning()) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"STMP: %lluticks | syt_interval=%d, tpf=%f\n", - m_last_timestamp, m_syt_interval, getTicksPerFrame()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "STMP: %lluticks | syt_interval=%d, tpf=%f\n", + m_last_timestamp, m_syt_interval, getTicksPerFrame()); } #endif @@ -182,5 +183,7 @@ unsigned int nevents, unsigned int offset) { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "(%p)->processReadBlock(%u, %u)\n",this,nevents,offset); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "(%p)->processReadBlock(%u, %u)\n", + this,nevents,offset); bool no_problem=true; Index: trunk/libffado/src/libstreaming/StreamProcessorManager.cpp =================================================================== --- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 864) +++ trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 866) @@ -711,5 +711,7 @@ while(period_not_ready) { - debugOutput( DEBUG_LEVEL_VERBOSE, "waiting for period (%d frames in buffer)...\n", m_SyncSource->getBufferFill()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "waiting for period (%d frames in buffer)...\n", + m_SyncSource->getBufferFill()); bool result; if(m_SyncSource->getType() == StreamProcessor::ePT_Receive) { @@ -770,10 +772,13 @@ // and the receive processors should have done their transfer. m_time_of_transfer = m_SyncSource->getTimeAtPeriod(); - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "transfer at %llu ticks...\n", - m_time_of_transfer); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "transfer at %llu ticks...\n", + m_time_of_transfer); // this is to notify the client of the delay that we introduced by waiting m_delayed_usecs = - m_SyncSource->getTimeUntilNextPeriodSignalUsecs(); - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "delayed for %d usecs...\n", m_delayed_usecs); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "delayed for %d usecs...\n", + m_delayed_usecs); #ifdef DEBUG @@ -789,6 +794,7 @@ xmt_bf = (*it)->getBufferFill(); } - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "XF at %011llu ticks, RBF=%d, XBF=%d, SUM=%d...\n", - m_time_of_transfer, rcv_bf, xmt_bf, rcv_bf+xmt_bf); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "XF at %011llu ticks, RBF=%d, XBF=%d, SUM=%d...\n", + m_time_of_transfer, rcv_bf, xmt_bf, rcv_bf+xmt_bf); // check if xruns occurred on the Iso side. @@ -832,5 +838,5 @@ */ bool StreamProcessorManager::transfer() { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); bool retval=true; retval &= transfer(StreamProcessor::ePT_Receive); @@ -849,5 +855,6 @@ bool StreamProcessorManager::transfer(enum StreamProcessor::eProcessorType t) { if(m_SyncSource == NULL) return false; - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "transfer(%d) at TS=%011llu (%03us %04uc %04ut)...\n", + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "transfer(%d) at TS=%011llu (%03us %04uc %04ut)...\n", t, m_time_of_transfer, (unsigned int)TICKS_TO_SECS(m_time_of_transfer), @@ -920,5 +927,6 @@ bool StreamProcessorManager::transferSilence(enum StreamProcessor::eProcessorType t) { if(m_SyncSource == NULL) return false; - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "transferSilence(%d) at TS=%011llu (%03us %04uc %04ut)...\n", + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, + "transferSilence(%d) at TS=%011llu (%03us %04uc %04ut)...\n", t, m_time_of_transfer, (unsigned int)TICKS_TO_SECS(m_time_of_transfer), Index: trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp =================================================================== --- trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp (revision 864) +++ trunk/libffado/src/libstreaming/generic/StreamProcessor.cpp (revision 866) @@ -388,6 +388,7 @@ if (result == eCRV_OK) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "RECV: CY=%04u TS=%011llu\n", - cycle, m_last_timestamp); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "RECV: CY=%04u TS=%011llu\n", + cycle, m_last_timestamp); // update some accounting m_last_good_cycle = cycle; @@ -502,5 +503,6 @@ } if (dropped_cycles > 0) { - debugWarning("(%p) dropped %d packets on cycle %u (last_cycle=%u, dropped=%d)\n", this, dropped_cycles, cycle, m_last_cycle, dropped); + debugWarning("(%p) dropped %d packets on cycle %u (last_cycle=%u, dropped=%d)\n", + this, dropped_cycles, cycle, m_last_cycle, dropped); m_dropped += dropped_cycles; // HACK: this should not be necessary, since the header generation functions should trigger the xrun. @@ -595,6 +597,7 @@ enum eChildReturnValue result = generateSilentPacketHeader(data, length, tag, sy, cycle, dropped_cycles, max_length); if (result == eCRV_Packet) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT SILENT: CY=%04u TS=%011llu\n", - cycle, m_last_timestamp); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "XMIT SILENT: CY=%04u TS=%011llu\n", + cycle, m_last_timestamp); // update some accounting m_last_good_cycle = cycle; @@ -646,6 +649,7 @@ enum eChildReturnValue result = generatePacketHeader(data, length, tag, sy, cycle, dropped_cycles, max_length); if (result == eCRV_Packet || result == eCRV_Defer) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT: CY=%04u TS=%011llu\n", - cycle, m_last_timestamp); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "XMIT: CY=%04u TS=%011llu\n", + cycle, m_last_timestamp); // update some accounting m_last_good_cycle = cycle; @@ -743,5 +747,7 @@ } - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "XMIT EMPTY: CY=%04u\n", cycle); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "XMIT EMPTY: CY=%04u\n", + cycle); generateEmptyPacketHeader(data, length, tag, sy, cycle, dropped_cycles, max_length); generateEmptyPacketData(data, length, tag, sy, cycle, dropped_cycles, max_length); @@ -759,5 +765,7 @@ bool StreamProcessor::getFrames(unsigned int nbframes, int64_t ts) { bool result; - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "%p.getFrames(%d, %11llu)", nbframes, ts); + debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, + "%p.getFrames(%d, %11llu)", + nbframes, ts); assert( getType() == ePT_Receive ); if(isDryRunning()) result = getFramesDry(nbframes, ts); @@ -788,6 +796,7 @@ lag_ticks = diffTicks(ts, ts_expected); lag_frames = (((float)lag_ticks) / srate); - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "stream (%p): drifts %6d ticks = %10.5f frames (rate=%10.5f), %lld, %llu, %d\n", - this, lag_ticks, lag_frames, srate, ts, ts_expected, fc); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "stream (%p): drifts %6d ticks = %10.5f frames (rate=%10.5f), %lld, %llu, %d\n", + this, lag_ticks, lag_frames, srate, ts, ts_expected, fc); if (lag_frames >= 1.0) { // the stream lags @@ -809,6 +818,7 @@ bool StreamProcessor::getFramesDry(unsigned int nbframes, int64_t ts) { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "stream (%p): dry run %d frames (@ ts=%lld)\n", - this, nbframes, ts); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "stream (%p): dry run %d frames (@ ts=%lld)\n", + this, nbframes, ts); // dry run on this side means that we put silence in all enabled ports // since there is do data put into the ringbuffer in the dry-running state @@ -829,5 +839,7 @@ { bool result; - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "%p.putFrames(%d, %11llu)", nbframes, ts); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "%p.putFrames(%d, %11llu)", + nbframes, ts); assert( getType() == ePT_Transmit ); if(isDryRunning()) result = putFramesDry(nbframes, ts); @@ -840,8 +852,11 @@ StreamProcessor::putFramesWet(unsigned int nbframes, int64_t ts) { - debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "StreamProcessor::putFramesWet(%d, %llu)\n", nbframes, ts); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "StreamProcessor::putFramesWet(%d, %llu)\n", + nbframes, ts); // transfer the data m_data_buffer->blockProcessWriteFrames(nbframes, ts); - debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, " New timestamp: %llu\n", ts); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + " New timestamp: %llu\n", ts); return true; // FIXME: what about failure? } @@ -850,5 +865,7 @@ StreamProcessor::putFramesDry(unsigned int nbframes, int64_t ts) { - debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "StreamProcessor::putFramesDry(%d, %llu)\n", nbframes, ts); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "StreamProcessor::putFramesDry(%d, %llu)\n", + nbframes, ts); // do nothing return true; @@ -858,5 +875,7 @@ StreamProcessor::putSilenceFrames(unsigned int nbframes, int64_t ts) { - debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "StreamProcessor::putSilenceFrames(%d, %llu)\n", nbframes, ts); + debugOutputExtreme(DEBUG_LEVEL_ULTRA_VERBOSE, + "StreamProcessor::putSilenceFrames(%d, %llu)\n", + nbframes, ts); size_t bytes_per_frame = getEventSize() * getEventsPerFrame(); @@ -1640,5 +1659,7 @@ bool StreamProcessor::waitForProduce(unsigned int nframes) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) wait ...\n", this, getTypeString()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p, %s) wait ...\n", + this, getTypeString()); struct timespec ts; int result; @@ -1662,9 +1683,12 @@ if (result == -1) { if (errno == ETIMEDOUT) { - debugOutput(DEBUG_LEVEL_VERBOSE, "(%p, %s) pthread_cond_timedwait() timed out\n", this, getTypeString()); + debugOutput(DEBUG_LEVEL_VERBOSE, + "(%p, %s) pthread_cond_timedwait() timed out\n", + this, getTypeString()); pthread_mutex_unlock(&m_activity_cond_lock); return false; } else { - debugError("(%p, %s) pthread_cond_timedwait error\n", this, getTypeString()); + debugError("(%p, %s) pthread_cond_timedwait error\n", + this, getTypeString()); pthread_mutex_unlock(&m_activity_cond_lock); return false; @@ -1686,5 +1710,7 @@ bool StreamProcessor::waitForConsume(unsigned int nframes) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) wait ...\n", this, getTypeString()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p, %s) wait ...\n", + this, getTypeString()); struct timespec ts; int result; @@ -1718,5 +1744,7 @@ } pthread_mutex_unlock(&m_activity_cond_lock); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p, %s) leave ...\n", this, getTypeString()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p, %s) leave ...\n", + this, getTypeString()); return true; } @@ -1737,5 +1765,4 @@ unsigned int bufferspace = m_data_buffer->getBufferSpace(); if(bufferspace >= nframes) { -// debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "enough space (%u)...\n", bufferspace); return true; } else return false; @@ -1768,5 +1795,4 @@ unsigned int bufferfill = m_data_buffer->getBufferFill(); if(bufferfill >= nframes) { -// debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "enough items (%u)...\n", bufferfill); return true; } else return false; Index: trunk/libffado/src/debugmodule/debugmodule.h =================================================================== --- trunk/libffado/src/debugmodule/debugmodule.h (revision 864) +++ trunk/libffado/src/debugmodule/debugmodule.h (revision 866) @@ -185,4 +185,24 @@ format, \ ##args ) + #define DEBUG_NORMAL( x ) x; + + #if DEBUG_EXTREME_ENABLE + #define debugOutputExtreme( level, format, args... ) \ + m_debugModule.print( level, \ + __FILE__, \ + __FUNCTION__, \ + __LINE__, \ + format, \ + ##args ) + #define debugOutputShortExtreme( level, format, args... ) \ + m_debugModule.printShort( level, \ + format, \ + ##args ) + #define DEBUG_EXTREME( x ) x; + #else + #define debugOutputExtreme( level, format, args... ) + #define debugOutputShortExtreme( level, format, args... ) + #define DEBUG_EXTREME( x ) + #endif #else @@ -190,4 +210,9 @@ #define debugOutput( level, format, args... ) #define debugOutputShort( level, format, args... ) + #define DEBUG_NORMAL( x ) + + #define debugOutputExtreme( level, format, args... ) + #define debugOutputShortExtreme( level, format, args... ) + #define DEBUG_EXTREME( x ) #endif Index: trunk/libffado/src/libutil/TimestampedBuffer.cpp =================================================================== --- trunk/libffado/src/libutil/TimestampedBuffer.cpp (revision 864) +++ trunk/libffado/src/libutil/TimestampedBuffer.cpp (revision 866) @@ -156,12 +156,13 @@ float TimestampedBuffer::calculateRate() { ffado_timestamp_t diff; - + diff=m_buffer_next_tail_timestamp - m_buffer_tail_timestamp; - - debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"getRate: %f/%f=%f\n", - (float)(diff), - (float)m_update_period, - ((float)(diff))/((float) m_update_period)); - + + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "getRate: %f/%f=%f\n", + (float)(diff), + (float)m_update_period, + ((float)(diff))/((float) m_update_period)); + // the maximal difference we can allow (64secs) const ffado_timestamp_t max=m_wrap_at/((ffado_timestamp_t)2); @@ -176,5 +177,6 @@ if (rate<0.0) debugError("rate < 0! (%f)\n",rate); if (fabsf(m_nominal_rate - rate)>(m_nominal_rate*0.1)) { - debugWarning("(%p) rate (%10.5f) more that 10%% off nominal (rate=%10.5f, diff="TIMESTAMP_FORMAT_SPEC", update_period=%d)\n", + debugWarning("(%p) rate (%10.5f) more that 10%% off nominal " + "(rate=%10.5f, diff="TIMESTAMP_FORMAT_SPEC", update_period=%d)\n", this, rate,m_nominal_rate,diff, m_update_period); @@ -532,6 +534,7 @@ */ bool TimestampedBuffer::blockProcessWriteFrames(unsigned int nbframes, ffado_timestamp_t ts) { - - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p) Writing %u frames for ts "TIMESTAMP_FORMAT_SPEC"\n", + this, nbframes, ts); int xrun; unsigned int offset = 0; @@ -642,5 +645,7 @@ bool TimestampedBuffer::blockProcessReadFrames(unsigned int nbframes) { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Reading %u from buffer (%p)...\n", nbframes, this); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p) Reading %u frames\n", + this, nbframes); int xrun; @@ -773,8 +778,8 @@ EXIT_CRITICAL_SECTION; - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "for (%p) to " - TIMESTAMP_FORMAT_SPEC" => "TIMESTAMP_FORMAT_SPEC", NTS=" - TIMESTAMP_FORMAT_SPEC", DLL2=%f, RATE=%f\n", - this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, getRate()); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "for (%p) to "TIMESTAMP_FORMAT_SPEC" => "TIMESTAMP_FORMAT_SPEC", " + "NTS="TIMESTAMP_FORMAT_SPEC", DLL2=%f, RATE=%f\n", + this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, getRate()); } @@ -820,182 +825,8 @@ EXIT_CRITICAL_SECTION; - debugOutput(DEBUG_LEVEL_VERBOSE, "for (%p) to "TIMESTAMP_FORMAT_SPEC" => " - TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC", DLL2=%f, RATE=%f\n", - this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, getRate()); - -} - -/** - * @brief Synchronize the buffer head to a specified timestamp - * - * Try to synchronize the buffer head to a specific timestamp. This - * can mean adding or removing samples to/from the buffer such that - * the buffer head aligns with the specified timestamp. The alignment - * is within ts +/- Tsample/2 - * - * @param target the timestamp to align to - * @return true if alignment succeeded, false if not - */ -bool -TimestampedBuffer::syncBufferHeadToTimestamp(ffado_timestamp_t target) -{ - uint64_t ts_head; - uint64_t ts_target=(uint64_t)target; - signed int fc; - int32_t lag_ticks; - float lag_frames; - - ffado_timestamp_t ts_head_tmp; - getBufferHeadTimestamp(&ts_head_tmp, &fc); - ts_head=(uint64_t)ts_head_tmp; - // if target > ts_head then the wanted buffer head timestamp - // is later than the actual. This means that we (might) have to drop - // some frames. - lag_ticks=diffTicks(ts_target, ts_head); - float rate=getRate(); - - assert(rate!=0.0); - - lag_frames=(((float)lag_ticks)/rate); - - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): HEAD=%llu, TS=%llu, diff=%ld = %10.5f frames (rate=%10.5f)\n", - this, ts_head, ts_target, lag_ticks, lag_frames, rate); - - if (lag_frames>=1.0) { - // the buffer head is too early - // ditch frames until the buffer head is on time - char dummy[getBytesPerFrame()]; // one frame of garbage - int frames_to_ditch=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): ditching %d frames (@ ts=%lld)\n",this,frames_to_ditch,ts_target); - - while (frames_to_ditch--) { - readFrames(1, dummy); - } - - } else if (lag_frames<=-1.0) { - // the buffer head is too late - // add some padding frames - int frames_to_add=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): adding %d frames (@ ts=%lld)\n",this,-frames_to_add,ts_target); - - while (frames_to_add++) { - writeDummyFrame(); - } - } - getBufferHeadTimestamp(&ts_head_tmp, &fc); - ts_head=(uint64_t)ts_head_tmp; - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): new HEAD=%llu, fc=%d, target=%llu, new diff=%lld\n", - this, ts_head, fc, ts_target, diffTicks(ts_target, ts_head)); - // FIXME: of course this doesn't always succeed - return true; -} - -/** - * @brief Synchronize the buffer tail to a specified timestamp - * - * Try to synchronize the buffer tail to a specific timestamp. This - * can mean adding or removing samples to/from the buffer such that - * the buffer tail aligns with the specified timestamp. The alignment - * is within ts +/- Tsample/2 - * - * @param target the timestamp to align to - * @return true if alignment succeeded, false if not - */ -bool -TimestampedBuffer::syncBufferTailToTimestamp(ffado_timestamp_t target) -{ - uint64_t ts_tail; - uint64_t ts_target=(uint64_t)target; - signed int fc; - int32_t lag_ticks; - float lag_frames; - - debugWarning("Untested\n"); - - ffado_timestamp_t ts_tail_tmp; - getBufferTailTimestamp(&ts_tail_tmp, &fc); - ts_tail=(uint64_t)ts_tail_tmp; - // if target < ts_tail then the wanted buffer head timestamp - // is later than the actual. This means that we (might) have to drop - // some frames. - lag_ticks=diffTicks(ts_tail, ts_target); - float rate=getRate(); - - assert(rate!=0.0); - - lag_frames=(((float)lag_ticks)/rate); - - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): HEAD=%llu, TS=%llu, diff=%ld = %10.5f frames (rate=%10.5f)\n", - this, ts_tail, ts_target, lag_ticks, lag_frames, rate); - - if (lag_frames>=1.0) { - // the buffer head is too early - // ditch frames until the buffer head is on time - char dummy[getBytesPerFrame()]; // one frame of garbage - int frames_to_ditch=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): ditching %d frames (@ ts=%lld)\n",this,frames_to_ditch,ts_target); - - while (frames_to_ditch--) { - readFrames(1, dummy); - } - - } else if (lag_frames<=-1.0) { - // the buffer head is too late - // add some padding frames - int frames_to_add=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): adding %d frames (@ ts=%lld)\n",this,-frames_to_add,ts_target); - - while (frames_to_add++) { - writeDummyFrame(); - } - } - getBufferHeadTimestamp(&ts_tail_tmp, &fc); - ts_tail=(uint64_t)ts_tail_tmp; - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): new HEAD=%llu, fc=%d, target=%llu, new diff=%lld\n", - this, ts_tail, fc, ts_target, diffTicks(ts_target, ts_tail)); - // FIXME: of course this doesn't always succeed - return true; -} - -/** - * @brief correct lag - * - * Try to synchronize the buffer tail to a specific timestamp. This - * can mean adding or removing samples to/from the buffer such that - * the buffer tail aligns with the specified timestamp. The alignment - * is within ts +/- Tsample/2 - * - * @param target the timestamp to align to - * @return true if alignment succeeded, false if not - */ -bool -TimestampedBuffer::syncCorrectLag(int64_t lag_ticks) -{ - float lag_frames; - float rate=getRate(); - assert(rate!=0.0); - - lag_frames=(((float)lag_ticks)/rate); - if (lag_frames >= 1.0) { - // the buffer head is too late - // add some padding frames - int frames_to_add=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): adding %d frames\n",this,frames_to_add); - - while (frames_to_add++) { - writeDummyFrame(); - } - } else if (lag_frames <= -1.0) { - // the buffer head is too early - // ditch frames until the buffer head is on time - char dummy[getBytesPerFrame()]; // one frame of garbage - int frames_to_ditch=(int)roundf(lag_frames); - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p): ditching %d frames\n",this,-frames_to_ditch); - - while (frames_to_ditch--) { - readFrames(1, dummy); - } - } - return true; + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "for (%p) to "TIMESTAMP_FORMAT_SPEC" => "TIMESTAMP_FORMAT_SPEC", " + "NTS="TIMESTAMP_FORMAT_SPEC", DLL2=%f, RATE=%f\n", + this, new_timestamp, ts, m_buffer_next_tail_timestamp, m_dll_e2, getRate()); } @@ -1158,5 +989,6 @@ debugOutput( DEBUG_LEVEL_VERBOSE, - "Updated ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC") to ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC")\n", + "Updated ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC") " + "to ("TIMESTAMP_FORMAT_SPEC","TIMESTAMP_FORMAT_SPEC")\n", m_buffer_tail_timestamp, m_buffer_next_tail_timestamp, m_buffer_tail_timestamp, pred_buffer_next_tail_timestamp); @@ -1172,9 +1004,13 @@ ffado_timestamp_t max_abs_diff = one_update_step * (1.0 + max_deviation); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " nbframes: %d, m_update_period: %d \n", nbframes, m_update_period); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " tail TS: "TIMESTAMP_FORMAT_SPEC", next tail TS: "TIMESTAMP_FORMAT_SPEC"\n", - m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, " new TS: "TIMESTAMP_FORMAT_SPEC", wrapped new TS: "TIMESTAMP_FORMAT_SPEC"\n", - new_timestamp, ts); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + " nbframes: %d, m_update_period: %d \n", + nbframes, m_update_period); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + " tail TS: "TIMESTAMP_FORMAT_SPEC", next tail TS: "TIMESTAMP_FORMAT_SPEC"\n", + m_buffer_tail_timestamp, m_buffer_next_tail_timestamp); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + " new TS: "TIMESTAMP_FORMAT_SPEC", wrapped new TS: "TIMESTAMP_FORMAT_SPEC"\n", + new_timestamp, ts); if (diff > max_abs_diff) { @@ -1188,13 +1024,15 @@ } - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "(%p): diff="TIMESTAMP_FORMAT_SPEC" ", - this, diff); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "(%p): diff="TIMESTAMP_FORMAT_SPEC" ", + this, diff); double err = diff; - - debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "diff2="TIMESTAMP_FORMAT_SPEC" err=%f\n", - diff, err); - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "B: FC=%10u, TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", - m_framecounter, m_buffer_tail_timestamp, pred_buffer_next_tail_timestamp); + debugOutputShortExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "diff2="TIMESTAMP_FORMAT_SPEC" err=%f\n", + diff, err); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "B: FC=%10u, TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC"\n", + m_framecounter, m_buffer_tail_timestamp, pred_buffer_next_tail_timestamp); ENTER_CRITICAL_SECTION; @@ -1205,11 +1043,13 @@ if (m_buffer_next_tail_timestamp >= m_wrap_at) { - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "Unwrapping next tail timestamp: "TIMESTAMP_FORMAT_SPEC"", - m_buffer_next_tail_timestamp); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "Unwrapping next tail timestamp: "TIMESTAMP_FORMAT_SPEC"", + m_buffer_next_tail_timestamp); m_buffer_next_tail_timestamp -= m_wrap_at; - debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, " => "TIMESTAMP_FORMAT_SPEC"\n", - m_buffer_next_tail_timestamp); + debugOutputShortExtreme(DEBUG_LEVEL_VERY_VERBOSE, + " => "TIMESTAMP_FORMAT_SPEC"\n", + m_buffer_next_tail_timestamp); } @@ -1217,6 +1057,7 @@ EXIT_CRITICAL_SECTION; - debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "A: TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC", DLLe2=%f, RATE=%f\n", - m_buffer_tail_timestamp, m_buffer_next_tail_timestamp, m_dll_e2, m_current_rate); + debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, + "A: TS="TIMESTAMP_FORMAT_SPEC", NTS="TIMESTAMP_FORMAT_SPEC", DLLe2=%f, RATE=%f\n", + m_buffer_tail_timestamp, m_buffer_next_tail_timestamp, m_dll_e2, m_current_rate); Index: trunk/libffado/src/libutil/TimestampedBuffer.h =================================================================== --- trunk/libffado/src/libutil/TimestampedBuffer.h (revision 864) +++ trunk/libffado/src/libutil/TimestampedBuffer.h (revision 866) @@ -131,9 +131,4 @@ void setBufferTailTimestamp ( ffado_timestamp_t new_timestamp ); void setBufferHeadTimestamp ( ffado_timestamp_t new_timestamp ); - - // sync related, also drops or add frames when necessary - bool syncBufferHeadToTimestamp ( ffado_timestamp_t ts ); - bool syncBufferTailToTimestamp ( ffado_timestamp_t ts ); - bool syncCorrectLag ( int64_t ts ); ffado_timestamp_t getTimestampFromTail ( int nframes ); Index: trunk/libffado/config.h.in =================================================================== --- trunk/libffado/config.h.in (revision 863) +++ trunk/libffado/config.h.in (revision 866) @@ -40,5 +40,9 @@ #define SHAREDIR "$SHAREDIR" -#define DEBUG_IMPLEMENT_BACKLOG 0 +#define DEBUG_IMPLEMENT_BACKLOG 0 + +// make this zero to disable the most extreme +// debug logging in the critical sections +#define DEBUG_EXTREME_ENABLE 0 #define IEEE1394SERVICE_USE_CYCLETIMER_DLL 1 Index: trunk/libffado/tests/test-ffado.cpp =================================================================== --- trunk/libffado/tests/test-ffado.cpp (revision 864) +++ trunk/libffado/tests/test-ffado.cpp (revision 866) @@ -204,5 +204,5 @@ } - printf("verbose level = %d\n", arguments.verbose); + printf("verbose level = %ld\n", arguments.verbose); setDebugLevel(arguments.verbose); @@ -275,5 +275,5 @@ int devices_on_bus = m_deviceManager->getNbDevices(); - printf(" port = %d, devices_on_bus = %d\n", arguments.port, devices_on_bus); + printf(" port = %ld, devices_on_bus = %d\n", arguments.port, devices_on_bus); for(i=0;i